Not getting the response body for http post request in android? -
not getting response body http post request in android.
mentioning userid, password in name value pairs , putting in httppost request
postrequest.setentity(new urlencodedformentity(namevaluepairs));
but on executing getting response sc_ok(200), response body null
.
one more problem if specify header in httpget or httppost's request using setheader()
function getting bad request (404) response.
please me in resolving above issue.
thanks & regards,
ssuman185
here's method easy post page, , getting response string. first param (the hashmap) key-value list of parameters want send. there no error handling you'll have that:
public static string dopost(hashmap<string,string> params, string url) { httppost httpost = new httppost(url); try { httpost.seturi(new uri(url)); } catch (urisyntaxexception e1) { // todo auto-generated catch block e1.printstacktrace(); } httpresponse response = null; list <namevaluepair> nvps = new arraylist <namevaluepair>(); set entryset = params.entryset(); iterator iterator = entryset.iterator(); log.d("posted url: ", url+" "); while(iterator.hasnext()) { map.entry mapentry = (map.entry)iterator.next(); string key = ((string)mapentry.getkey()).tostring(); string value = (string)mapentry.getvalue(); nvps.add(new basicnamevaluepair(key, value)); log.d("posted param: ", key+" = "+value); } try { httpost.setentity(new urlencodedformentity(nvps, http.utf_8)); try { httpost.seturi(new uri(url)); } catch (urisyntaxexception e1) { // todo auto-generated catch block e1.printstacktrace(); } response = getclient().execute(httpost); httpentity entity = response.getentity(); return convertstreamtostring(entity.getcontent()); } catch (exception e) { // connection error occurred, nothing can e.printstacktrace(); } return null; }
Comments
Post a Comment