简体   繁体   中英

java.io.IOException: Server returned HTTP response code: 403 for URL: in java

i want get json from this url

but get error like this :

java.io.IOException: Server returned HTTP response code: 403 for URL: http://test.dotconnect.io/data_api/reports/1bf4bc70b31d4d92b50a6d965c52fcec

this is my complete code :

InputStream is = null;
JsonReader rdr = null;
OutputStreamWriter out = null;
String path = "http://test.dotconnect.io/data_api/reports/";
int timeout = 6000000;
String key ="Authorization : 402c669e45534f868f5d2dd53c8e345f,a80797e0df9c4696b5494635dae02461";
URL url = new URL(path+request.getParameter("reportTaskToken"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setDoInput(true); // Triggers GET
connection.setDoOutput(true);// Triggers POST
connection.setRequestProperty("Authorization", key);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
System.setProperty("http.agent", "Chrome");
System.setProperty("http.proxyHost", "proxy.smmf.co.id");
System.setProperty("http.proxyPort", "8080"); 
out = new OutputStreamWriter(connection.getOutputStream());
out.flush();
out.close();
is = connection.getInputStream();
rdr = Json.createReader(is);

but when i try in postman it's work, I've read on stackoverflow but still have errors like that

Someone could help me?

Thank You, a greeting,

Try modifying key variable from

String key ="Authorization : 402c669e45534f868f5d2dd53c8e345f,a80797e0df9c4696b5494635dae02461";
// to something like below
String key ="402c669e45534f868f5d2dd53c8e345f,a80797e0df9c4696b5494635dae02461";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM