【发布时间】:2014-09-05 11:29:14
【问题描述】:
我是编程新手,请耐心等待 - 我成功地对 Web 服务进行了 POST,但现在我想查看返回的数据,该怎么做?这是我的代码:
try {
String data = "{\"params\":{\"stopName\":\"%lauro linhares%\"}}";
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("WKD4N7YMA1uiM8V", "DtdTtzMLQlA0hk2C1Yi5pLyVIlAQ68"));
//
DefaultHttpClient http = new DefaultHttpClient();
http.setCredentialsProvider(credProvider);
HttpPost post = new HttpPost("https://api.appglu.com/v1/queries/findRoutesByStopName/run");
try {
post.setEntity(new StringEntity(data, "UTF8"));
} catch (UnsupportedEncodingException e) {
System.out.println( "UnsupportedEncoding: "+ e);
}
post.addHeader("Content-Type", "application/json");
post.addHeader("X-AppGlu-Environment", "staging");
HttpResponse response = http.execute(post);
System.out.println("hi! This is what we get back:"+response.getStatusLine().toString()+", "+response.getEntity().toString());
//Hi! This is what we get back:HTTP/1.1 200 OK, org.apache.http.conn.BasicManagedEntity@4246cb88
// got status 200, which is good, but what can
// I write next to see the
//data i got back from web service ?
} catch (ClientProtocolException e) {
//
System.out.println( "nadir Client protocol exception" + e);
} catch (IOException e) {
//
System.out.println( "nadir IOException"+ e);
}
【问题讨论】:
标签: java android apache http-headers