iphone - Get a request twice? -
i using below code send request web-service , response , here got request twice @ time ,i dont did mistake,help me come out issue. in advance.
nsstring *poststr=[nsstring stringwithformat:@"&cname=%@&conname=%@&email=%@",companynametxt.text,contactnametxt.text,contactemailtxt.text]; nslog(@"poststr %@",poststr); nsdata *postdata = [poststr datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%d", [postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring: @"web servicess"]]; [request sethttpmethod:@"post"]; [request sethttpbody:postdata]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; nsurlconnection *theconnection=[[nsurlconnection alloc] initwithrequest:request delegate:self]; nslog(@"data%@",theconnection); [theconnection release]; nserror *error; nsurlresponse *response; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nsstring *filenamestr=[[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; nslog(@"filenamestr %@",filenamestr);
you making 2 separate calls
nsurlconnection *theconnection=[[nsurlconnection alloc] initwithrequest:request delegate:self];
and
nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error];
use either 1 of them not both.
Comments
Post a Comment