Android : Http post get response Android

on Monday, October 13, 2014


I want to retrieve some data from an external web page. When I'm navigating on it and I click to show this data, I see from the developer console (under "network") that a http post call is been making. If I open it, I can see the data I want retrieve from my android app and I want to get that string response.


But I don't know how to "build" the http post request. This is my code:



HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://portus.puertos.es/Portus_RT/portusgwt/rpc");

httppost.addHeader("Connection", "keep-alive");
httppost.addHeader("Content-Length", "172");
httppost.addHeader("X-GWT-Module-Base", "http://portus.puertos.es/Portus_RT/portusgwt/");
httppost.addHeader("X-GWT-Permutation", "3DEDE3A69CBBE62D4C3F58BF7278538F");
httppost.addHeader("Origin", "http://portus.puertos.es");
httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
httppost.addHeader("Accept", "*/*");
httppost.addHeader("Referer", "http://portus.puertos.es/Portus_RT/?locale=es");
httppost.addHeader("Accept-Encoding", "gzip,deflate");
httppost.addHeader("Accept-Language", "en-US,en;q=0.8,es;q=0.6,ca;q=0.4");
httppost.addHeader("AlexaToolbar-ALX_NS_PH", "AlexaToolbar/alxg-3.3");
httppost.addHeader("Content-Type", "text/x-gwt-rpc; charset=UTF-8");
httppost.addHeader("Host", "portus.puertos.es");

//I think I need to add the payload here
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("", ""));

try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.d("TAG", EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}


I really don't know about http protocols, so I don't know what data of the http post request (that I can see from the developer console) I need to add. This is the http post request I see: enter image description here


I'm not sure If I need to add all the headers and how to add the payload. Even I do not know if I can do this, so I will be very grateful I anyone can guide me some


Thanks!!


0 comments:

Post a Comment