[英]Before I can get JSON file, how can I build correct connection with getting 503 Server Error
我正在尝试几天来获得连接到Yobit公共API的HTTPS连接。 我不知道我的代码发生了什么。 我尝试了很多不同的例子,但是在Yobit上没有任何效果。 我试过的那些代码和例子,他们要么给出411,503错误,要么给出MalFormException:没有协议。 谁能帮我? 我在Java上使用HTTPS或Web编程的经验非常有限。 如果任何人可以提供我的解决方案和参考资料,我将非常感激。
public void buildHttpsConnection()
{
try {
URL url = new URL("https://yobit.net/api/3/info");
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("user-Agent", "Mozilla/5.0 (compatible; JAVA AWT)");
con.setRequestProperty("Accept-Language","en-US,en;q=0.5");
con.setDoOutput(true);
con.setUseCaches(false);
System.out.println(con.getResponseCode());
}
catch (Exception e)
{
e.printStackTrace();
}
}
尝试使用“ https://www.yobit.net/api/3/info”URL而不是“ https://yobit.net/api/3/info ”它会给你相同的结果。 您可以从浏览器窗口验证它。
请查看下面的代码段。
try {
URL url = null;
try {
url = new URL("https://www.yobit.net/api/3/info");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
try {
con.setRequestMethod("GET");
} catch (ProtocolException e1) {
e1.printStackTrace();
}
con.setRequestProperty("user-Agent", "Mozilla/5.0 (compatible; JAVA AWT)");
con.setRequestProperty("Accept-Language","en-US,en;q=0.5");
con.setDoOutput(true);
con.setUseCaches(false);
con.connect();
try {
System.out.println(con.getResponseCode());
} catch (IOException e1) {
e1.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.