ios - i have issues in posting a json object -
nsstring *username = @"user"; nsstring *password = @"password"; nsmutabledictionary *dictionnary = [nsmutabledictionary dictionary]; [dictionnary setobject:username forkey:@"user_email"]; [dictionnary setobject:password forkey:@"user_password"]; nslog(@".....%@....",dictionnary); nserror *error = nil; nsdata *jsondata = [nsjsonserialization datawithjsonobject:dictionnary options:kniloptions error:&error]; nsstring *urlstring = @"http://abcd.com/svcs/wsuserservice.svc/mobsignin"; nsurl *url = [nsurl urlwithstring:urlstring]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url]; [request sethttpmethod:@"post"]; [request sethttpbody:jsondata]; nsurlresponse *response = null; nserror *requesterror = null; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&requesterror]; nsstring *responsestring = [[nsstring alloc] initwithdata:responsedata encoding:nsasciistringencoding] ; nslog(@"%@", responsestring);
i want post json object has username , password web service.. gives vague output.. can me on this
output: 2013-05-14 18:50:17.155 uwui[6226:11303] .....{ "user_email" = user; "user_password" = password; }....
2013-05-14 18:50:18.233 uwui[6226:11303]  **
followed xml format content
**
nsstring *un = @"user"; nsstring *pwd = @"password"; nsmutabledictionary *dictionnary = [nsmutabledictionary dictionary]; [dictionnary setobject:un forkey:@"un"]; [dictionnary setobject:pwd forkey:@"pwd"]; nslog(@"dictionnary...%@", dictionnary); nserror *error = nil; nsdata *jsondata = [nsjsonserialization datawithjsonobject:dictionnary options:kniloptions error:&error]; nsstring *urlstring = @"http://abcd.com/svcs/wsuserservice.svc/mobsignin"; nsurl *url = [nsurl urlwithstring:urlstring]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url]; [request sethttpmethod:@"post"]; [request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; [request sethttpbody:jsondata]; nsurlresponse *response = null; nserror *requesterror = null; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&requesterror]; nsstring *responsestring = [[nsstring alloc] initwithdata:responsedata encoding:nsutf8stringencoding] ; nslog(@"%@", responsestring);
Comments
Post a Comment