ashutiwari4

Untitled

Mar 23rd, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Use this code in doInBackground
  2.  
  3. HttpClient client = new DefaultHttpClient();
  4. String urlx = "http://10.0.2.2:64466/api/Products/1";
  5. URL url = new URL(urlx);
  6. URI uri = new URI(url.getProtocol(), url.getUserInfo(),
  7. url.getHost(), url.getPort(), url.getPath(),
  8. url.getQuery(), url.getRef());
  9. url = uri.toURL();
  10.  
  11. Log.v("Async Task", "url is: " + url);
  12.  
  13. HttpGet request = new HttpGet(url.toString());
  14. HttpResponse response = client.execute(request);
  15. StatusLine statusLine = response.getStatusLine();
  16. int statusCode = statusLine.getStatusCode();
  17. if (statusCode == 200) {
  18. HttpEntity entity = response.getEntity();
  19.  
  20. if (entity != null) {
  21. InputStream instream = entity.getContent();
  22. String jsonResult = RestClient
  23. .convertStreamToString(instream);
  24. Log.e("Result","Json: "+jsonResult)
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment