ios - How to post SOAP data to server in objective c -


i trying post data server give me error code

-(ibaction)loginbtnclk:(id)sender {   [self senddatatoserver :@"post"]; }  -(void) senddatatoserver : (nsstring *) method{      int userid=0;     nsstring *usercode  = usertf.text;     int roleid=12;     nsstring *salutation = @"mr.";     nsstring *firstname=frstnmetf.text;     nsstring *lastname =lstnametf.text;     nsstring *pwd=paswrdtf.text;     nsstring *emailid=@"abc@gmail.com";     nsstring *mobile=@"9876543210";     nsstring *usertype=@"4";     int empid=0;     int zoneid=575;      nsstring *post = [nsstring stringwithformat:@"userid=%d&usercode=%@&roleid=%d&salutation=%@&firstname=%@&lastname=%@&pwd=%@emailid=%@&mobile=%@&usertype=%@&empid=%d&zoneid=%d",userid,usercode,roleid,salutation,firstname,lastname,pwd,emailid,mobile,usertype,empid,zoneid];     nsdata *postdata = [post datausingencoding:nsasciistringencoding allowlossyconversion:yes];      nsstring *postlength = [nsstring stringwithformat:@"%lu",(unsigned long)[post length]];     nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init];     [request seturl:[nsurl urlwithstring:@"http://url?op=insert_userdata"]];     [request sethttpmethod:@"post"];     [request setvalue:postlength forhttpheaderfield:@"content-length"];     nslog(@"url = %@",request);     [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];     [request sethttpbody:postdata];     nsurlconnection *conn = [[nsurlconnection alloc] initwithrequest:request delegate:self];     nslog(@"connection link =%@",conn);     if(conn) {         mutabledata =[[nsmutabledata alloc] init];         nslog(@"connection successful");     } else {         nslog(@"connection not made");     }  }  #pragma mark nsurlconnection delegates  -(void) connection:(nsurlconnection *) connection didreceiveresponse:(nsurlresponse *)response {     [mutabledata setlength:0]; }  -(void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [mutabledata appenddata:data]; }  -(void) connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     serverresponse.text = no_connection;     return; }  -(void)connectiondidfinishloading:(nsurlconnection *)connection {      nsxmlparser *mynsxmlparserfloorobj=[[nsxmlparser alloc]initwithdata:mutabledata];     mynsxmlparserfloorobj.delegate=self;     [mynsxmlparserfloorobj parse];     nslog(@"%@",mynsxmlparserfloorobj.parsererror);     nsstring *responsestringwithencoded = [[nsstring alloc] initwithdata: mutabledata encoding:nsutf8stringencoding];     //nslog(@"response server : %@", responsestringwithencoded);     nsattributedstring * attrstr = [[nsattributedstring alloc] initwithdata:[responsestringwithencoded datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil];     serverresponse.attributedtext = attrstr; } -(void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict {     if([elementname isequaltostring:@"insert_userdata"])     {         mydataclassobj=[[mydata alloc]init];     } } -(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string {     mymutablestringobj=[[nsmutablestring alloc]initwithstring:string];     nslog(@"array string: %@",mymutablestringobj);     nsdata *data = [mymutablestringobj datausingencoding:nsutf8stringencoding];     responsedict = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil];     nslog(@"json data = %@",responsedict);   } -(void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname {  } 

when trying post data shows me error

2016-06-28 16:37:07.793 webservicedemo[5407:137315] connection successful 2016-06-28 16:37:13.035 webservicedemo[5407:137315] array string: soap:receiver 2016-06-28 16:37:13.035 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:15.241 webservicedemo[5407:137315] array string: system.web.services.protocols.soapexception: server unable process request. --- 2016-06-28 16:37:15.242 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:17.680 webservicedemo[5407:137315] array string: > 2016-06-28 16:37:17.680 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:19.835 webservicedemo[5407:137315] array string:  system.xml.xmlexception: data @ root level invalid. line 1, position 1. 2016-06-28 16:37:19.835 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:21.555 webservicedemo[5407:137315] array string:     @ system.xml.xmltextreaderimpl.throw(string res, string arg) 2016-06-28 16:37:21.556 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:22.808 webservicedemo[5407:137315] array string:     @ system.xml.xmltextreaderimpl.parserootlevelwhitespace() 2016-06-28 16:37:22.808 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:23.810 webservicedemo[5407:137315] array string:     @ system.xml.xmltextreaderimpl.parsedocumentcontent() 2016-06-28 16:37:23.811 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:24.696 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.soapserverprotocol.soapenvelopereader.read() 2016-06-28 16:37:24.696 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:25.532 webservicedemo[5407:137315] array string:     @ system.xml.xmlreader.movetocontent() 2016-06-28 16:37:25.532 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:26.200 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.soapserverprotocol.soapenvelopereader.movetocontent() 2016-06-28 16:37:26.200 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:26.986 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.soapserverprotocolhelper.getrequestelement() 2016-06-28 16:37:26.986 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:27.820 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.soap12serverprotocolhelper.routerequest() 2016-06-28 16:37:27.820 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:28.705 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.soapserverprotocol.initialize() 2016-06-28 16:37:28.705 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:29.474 webservicedemo[5407:137315] array string:     @ system.web.services.protocols.serverprotocolfactory.create(type type, httpcontext context, httprequest request, httpresponse response, boolean 2016-06-28 16:37:29.475 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:30.309 webservicedemo[5407:137315] array string: & 2016-06-28 16:37:30.309 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:31.129 webservicedemo[5407:137315] array string:  abortprocessing) 2016-06-28 16:37:31.130 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:31.881 webservicedemo[5407:137315] array string:     --- end of inner exception stack trace --- 2016-06-28 16:37:31.882 webservicedemo[5407:137315] json data = (null) 2016-06-28 16:37:31.882 webservicedemo[5407:137315] (null) 

i not getting issue is. data retrive server @ time of posting shows me error. me.

it' run. change code

-(ibaction)senddatausingget:(id)sender{      [self senddatatoserver : @"get"]; } -(void) senddatatoserver : (nsstring *) method{      int userid=idtxt.text;     nsstring *usercode  = usertf.text;      nsstring *soapmessage = [nsstring stringwithformat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"                              "<soap:envelope xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"                              "<soap:body>"                              "<method xmlns=\"http://tempuri.org/\">"                              "<paramener1>%d</paramener1>"                              "<paramener2>%@</paramener2>"                              "</method>"                              "</soap:body>"                              "</soap:envelope>",userid,usercode];      nsdata *postdata = [soapmessage datausingencoding:nsasciistringencoding allowlossyconversion:yes];      nsstring *postlength = [nsstring stringwithformat:@"%lu",(unsigned long)[soapmessage length]];     nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init];     [request seturl:[nsurl urlwithstring:@"http://url/method"]];     [request sethttpmethod:@"post"];     [request addvalue: @"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"];     [request setvalue:postlength forhttpheaderfield:@"content-length"];     nslog(@"url = %@",request);     //[request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];     [request sethttpbody:postdata];     nsurlconnection *conn = [[nsurlconnection alloc] initwithrequest:request delegate:self];     nslog(@"connection link =%@",conn);     if(conn) {         mutabledata =[[nsmutabledata alloc] init];         nslog(@"connection successful");     } else {         nslog(@"connection not made");     }  }  #pragma mark nsurlconnection delegates  -(void) connection:(nsurlconnection *) connection didreceiveresponse:(nsurlresponse *)response {     [mutabledata setlength:0]; }  -(void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [mutabledata appenddata:data]; }  -(void) connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     serverresponse.text = no_connection;     return; } -(void)connectiondidfinishloading:(nsurlconnection *)connection {      nsxmlparser *mynsxmlparserfloorobj=[[nsxmlparser alloc]initwithdata:mutabledata];     mynsxmlparserfloorobj.delegate=self;     [mynsxmlparserfloorobj parse];     nslog(@"%@",mynsxmlparserfloorobj.parsererror);     nsstring *responsestringwithencoded = [[nsstring alloc] initwithdata: mutabledata encoding:nsutf8stringencoding];     //nslog(@"response server : %@", responsestringwithencoded);     nsattributedstring * attrstr = [[nsattributedstring alloc] initwithdata:[responsestringwithencoded datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil];     serverresponse.attributedtext = attrstr; } -(void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict {     if([elementname isequaltostring:@"insert_userdata"])     {         mydataclassobj=[[mydata alloc]init];     } } -(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string {     mymutablestringobj=[[nsmutablestring alloc]initwithstring:string];     nslog(@"array string: %@",mymutablestringobj);     nsdata *data = [mymutablestringobj datausingencoding:nsutf8stringencoding];     responsedict = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil];     nslog(@"json data = %@",responsedict);   } -(void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname {  } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -