开发者

HTTPS request/response in Android

开发者 https://www.devze.com 2023-01-20 15:32 出处:网络
Need to send a POST request to开发者_Python百科 a Service provider using HTTPS protocol, response from the service provider will be an xml file, need to read that also.You could start by taking a look

Need to send a POST request to开发者_Python百科 a Service provider using HTTPS protocol, response from the service provider will be an xml file, need to read that also.


You could start by taking a look at AndroidHttpClient and at HttpPost.

Something like this should work:

 final AndroidHttpClient httpClient = AndroidHttpClient.newInstance(this.getClass().getSimpleName());
 HttpResponse httpresponse   = null;
 HttpEntity httpentity       = null;
 HttpUriRequest httprequest = new HttpPost("https://...");
 byte[] xmlByteArray = null;

 if ((httpresponse = httpClient.execute(httprequest)) != null) {
  if ((httpentity = httpresponse.getEntity()) != null) {
   xmlByteArray = EntityUtils.toByteArray(httpentity);
  }
 }

Also, my RestClient on github might be useful. Note: I use GET to retrieve the data, so YMMV.

0

精彩评论

暂无评论...
验证码 换一张
取 消