我正在尝试使用JAVA调用Webservices API,但我的连接问题可能是由于代理问题。
我已经使用C#WPF应用程序完成了它,并且为了避免连接问题,我在App.config文件上设置了以下选项
<system.net>
<defaultProxy useDefaultCredentials="true"></defaultProxy>
我找不到在JAVA上进行相同设置的方法,我的连接被拒绝了:
您知道如何设置默认代理吗?
JAVA代码
/**
* Executes the request and returns its response.
*
* @return the request's response
* @throws IOException if the underlying {@link HttpsURLConnection} could
* not be set up or executed
*/
public String execute() throws IOException {
HttpsURLConnection connection = null;
try {
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
// write POST data to request
// Exception is raised at this level
if (postData != null && !postData.toString().isEmpty()) {
connection.setDoOutput(true);
try (OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()))
{
out.write(postData.toString());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
// execute request and read response
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
return response.toString();
}
}
finally {
connection.disconnect();
}
}
非常感谢你的帮助