[英]Before I can get JSON file, how can I build correct connection with getting 503 Server Error
I was trying several days to get HTTPS connection right to connect to Yobit public API. 我正在尝试几天来获得连接到Yobit公共API的HTTPS连接。 I don't know what happen to my code.
我不知道我的代码发生了什么。 I have tried so many different examples but nothing works out on Yobit.
我尝试了很多不同的例子,但是在Yobit上没有任何效果。 Those codes and examples I have tried, they either give 411, 503 error or MalFormException:no protocol.
我试过的那些代码和例子,他们要么给出411,503错误,要么给出MalFormException:没有协议。 Can anyone help me?
谁能帮我? I have very limited experience with HTTPS or web programming on Java.
我在Java上使用HTTPS或Web编程的经验非常有限。 If any one can provide me solutions and references, I will really appreciate that.
如果任何人可以提供我的解决方案和参考资料,我将非常感激。
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();
}
}
Try to use " https://www.yobit.net/api/3/info " URL Instead of " https://yobit.net/api/3/info " It will give you the same result. 尝试使用“ https://www.yobit.net/api/3/info”URL而不是“ https://yobit.net/api/3/info ”它会给你相同的结果。 You can validate it from the browser Window.
您可以从浏览器窗口验证它。
Check below snippet. 请查看下面的代码段。
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.