android - send and fetch data from server not working -


my android project want send json data (as arraylist),with header..

and read server response string..

defaulthttpclient deprecated..so,i using httpurlconnection..

here code:-

@override public string signup(string name, string phno) throws exception {    string url="http://address/androidproject/usersignup";   // instantiate , initialise signupform    form suf = new form(name, phno);  // store suf in list list<namevaluepair> pairs = new arraylist<namevaluepair>(1);  // create k,v sent  pairs.add(new basicnamevaluepair("suf", new gson().tojson(suf)));   try  {   url  url1 = new url(url);  httpurlconnection connection = (httpurlconnection) url1.openconnection();  //encoded pairs  httpentity requestentity = new urlencodedformentity(pairs);   connection.setrequestmethod("post");  //add header  connection.setrequestproperty("id", myid);   connection.setdooutput(true);  //send data  outputstreamwriter writer =         new outputstreamwriter(connection.getoutputstream());   writer.write(requestentity.tostring());  writer.flush();  connection.connect();   // read output server  string content =  connection.getresponsemessage();  int responsecode = connection.getresponsecode();  // if response httpstatus not 'created' if (responsecode != 201) {  // throw error message application  }  // can return authtoken. return content;  } catch (exception e) { e.printstacktrace();  throw e; } } 

i getting error:

server response string: required string parameter 'suf' not present signup access server error: java.lang.illegalstateexception: expected begin_object string @ line 1 column 1 

but code not sending data server..where problem??why cannot post value??what missed?


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -