objective c - How to use .NET web service in iPhone, with POST method? -
i communicating .net web service in iphone application, using post method, not getting xml response. here code:
nsurl *url = [nsurl urlwithstring:[nsstring stringwithformat:@"myserver/eventservice.svc"]]; nsstring *api = @"/registeruser"; nsdata *body = [[nsstring stringwithformat:@"%@/%@/%@/%@/%@/%@/%@/%@/%@", api, txtfname.text ,txtlname.text, txtuname.text, txtemail.text, txtpassword.text, txtcity.text, txtstate.text, str] datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nslog(@"url %@",url); nslog(@"body %@",[nsstring stringwithformat:@"%@/%@/%@/%@/%@/%@/%@/%@/%@", api, txtfname.text, txtlname.text, txtuname.text, txtemail.text, txtpassword.text, txtcity.text, txtstate.text, str]); nsmutableurlrequest *request = [[[nsmutableurlrequest alloc] init] autorelease]; [request seturl:url]; [request sethttpbody:body]; [request setvalue:@"text/xml" forhttpheaderfield:@"content-type"]; nslog(@"body len %d",[body length]); nsstring *postlength = [nsstring stringwithformat:@"%d", [body length]]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request sethttpmethod:@"post"]; nserror *error; nsurlresponse *response; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nsstring *xmlstring=[[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; nslog(@"data %@",xmlstring);
please me. in advance.
i have done following.
nsurl *url=[nsurl urlwithstring:[nsstring stringwithformat:@"myserver/eventservice.svc/webservice/%@/%@",para1,para2]]; nsmutableurlrequest *request = [[[nsmutableurlrequest alloc] init] autorelease]; [request seturl:url]; [request addvalue:@"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"]; [request addvalue:0 forhttpheaderfield:@"content-length"]; [request sethttpmethod:@"post"]; nserror *error; nsurlresponse *response; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nsstring *xmlstring=[[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; nslog(@"data %@",xmlstring);
Comments
Post a Comment