我正在使用下面的代码来制作一个http客户端,我面临着执行方法的问题,它在那里卡住了。HTTPPost使用错误在执行方法
public static final HttpHost target = new HttpHost("test.xyz.com", 443, "https");
public static void test()
{
HttpEntity responseEntity = null;
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("/xyz/test");
System.out.println("post is " +post.getRequestLine());
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
AuthScope authScope = new AuthScope(target.getHostName(), target.getPort());
System.out.println("auth scope is " +authScope);
client.getCredentialsProvider().setCredentials(authScope, credentials);
//i am passing a xml here
post.setEntity(new StringEntity(xml, "UTF-8"));
post.addHeader("Content-Type", "application/xml");
post.addHeader("Accept", "application/xml");
System.out.println("post " +post.getAllHeaders().length);
HttpResponse response = client.execute(target, post); //getting stuck here no response at all
System.out.println("response " +response.getStatusLine());
responseEntity = response.getEntity();
System.out.println("response entity " +responseEntity);
String responseXmlString = EntityUtils.toString(responseEntity);
System.out.println("response" +responseXmlString);
}
我在这里
HttpResponse response = client.execute(target, post);
面临的问题可能是什么问题?
问题是代码卡在client.execut方法它不移动furthur既没有得到任何response.Do我必须设置任何代理?
问题是代码卡在client.execut方法它不移动furthur我也没有得到任何回应。我是否设置任何代理? – sarah 2009-12-19 10:15:31
当您运行测试时,您是否有可以接收该帖子的目标设置?执行可能只是忙于尝试将数据传送到无法写入的套接字。 – rsp 2009-12-19 11:02:50
ya目标设置为接收数据。服务器可能忙于接收数据的时间长度,我等待最多5分钟执行 – sarah 2009-12-19 11:16:24