For Workers & Pages, what is the name of the domain?
chinese-workday-calendar.aops.io
What is the error number?
403
What is the error message?
403
What is the issue or error you’re encountering
Get 403 when access to public R2 bucket via custom domain url via HttpURLConnection in Java
What are the steps to reproduce the issue?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
class Scratch {
public static void main(String[] args) throws IOException {
URL url = new URL(args[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setConnectTimeout(3000);
connection.setReadTimeout(10000);
connection.connect();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
}
$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
$ javac scratch.java
$ java Scratch https://chinese-workday-calendar.aops.io/years.properties
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: https://chinese-workday-calendar.aops.io/years.properties
You could also reproduce via curl add a explicit User-Agent header:
$ curl -i https://chinese-workday-calendar.aops.io/years.properties -H 'User-Agent: Java/1.8.0_201'
HTTP/2 403
date: Thu, 13 Feb 2025 01:49:32 GMT
content-type: text/plain; charset=UTF-8
content-length: 16
x-frame-options: SAMEORIGIN
referrer-policy: same-origin
cache-control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
expires: Thu, 01 Jan 1970 00:00:01 GMT
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=MTWV3ZSVlJtqeKYiv3dxxz0LSevet0RcpauwmLuj1CAPWstZTxKqH9CiIaGGQtnTgqV2StklgSU9pkpdLisFc0nb6Ddzu%2BlrvzorvyAJrY2200ZnUCMOXgSM8Hxpl%2FsZrcV8v8F26ZxOd1fVqhQHXm66ng%3D%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 91112993e9060ed8-HKG
alt-svc: h3=":443"; ma=86400
server-timing: cfL4;desc="?proto=TCP&rtt=38371&min_rtt=38152&rtt_var=11163&sent=6&recv=10&lost=0&retrans=0&sent_bytes=3467&recv_bytes=816&delivery_rate=72719&cwnd=234&unsent_bytes=0&cid=31599be2002c75c7&ts=53&x=0"
error code: 1010
Workaround:
Explicit set a user-agent header via java.net.URLConnection#setRequestProperty
like this: connection.setRequestProperty("User-Agent", "Mozilla/5.0");
Looks like the server just met recognization issue for user-agent header with this pattern: Java/{number}.{number}.{number}