【发布时间】:2015-02-11 10:37:13
【问题描述】:
我正在尝试编写程序以使用提供商的 REST 服务。
我的问题是有一个带有用户/密码身份验证的代理,我无法解决这个问题。
不使用代理也可以,但我需要使用代理。
这是我没有代理配置的代码。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
@SuppressWarnings("deprecation")
public class callAPI {
public callAPI() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) throws ClientProtocolException,
IOException {
//System.setProperty("java.net.useSystemProxies", "true");
@SuppressWarnings("resource")
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(
"URL");
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}
我已阅读所有帖子并尝试在我的代码中执行此操作,但总是遇到相同的错误(连接被拒绝)。
提前致谢!
【问题讨论】: