json - Issue with httpPost.setEntity Android -


i'm trying send data android application server using following method:

public jsonobject  getjsonfromurl(string url, list<namevaluepair> params) {          try{             // defaulthttpclient             defaulthttpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost(url);             (int i=0; i<params.size(); i++) {                 log.v("askj",params.get(i).tostring());             }             httppost.setentity(new urlencodedformentity(params));              try {                 log.v("askj","http entity : " + convertstreamtostring(httppost.getentity().getcontent()));             }catch (exception e){                 e.printstacktrace();             }              httpresponse httpresponse = httpclient.execute(httppost);             httpentity httpentity = httpresponse.getentity();             = httpentity.getcontent();          } catch (unsupportedencodingexception e) {             e.printstacktrace();         } catch (clientprotocolexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }          try {             bufferedreader reader = new bufferedreader(new inputstreamreader(                     is, "iso-8859-1"), 8);             stringbuilder sb = new stringbuilder();             string line = null;             while ((line = reader.readline()) != null) {                 sb.append(line + "\n");             }             is.close();             json = sb.tostring();             log.v("askj",json);             log.e("json", json);         } catch (exception e) {             log.e("buffer error", "error converting result " + e.tostring());         }          // try parse string json object         try {             jobj = new jsonobject(json);         } catch (jsonexception e) {             log.e("json parser", "error parsing data " + e.tostring());         }          // return json string         return jobj;      } 

i know sure i'm getting parameters right, url fine, bit of code httppost.setentity(new urlencodedformentity(params)); doesn't work. url being accessed without params. httpclient.execute(httppost); accesing initial url without params. how can solve ? tried use uri instead of setentity don't know how append variable numbers of parameters @ once.

edit: tested service postman , website can handle post requests, problem jsonparser.

try specifying encoding format this:

httppost.setentity(new urlencodedformentity(params, "utf-8")); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -