ios - Posting to the webserver the data in iPhone -
i searched can't solve problem .here want post data server. have 1 user default, textview , textfield. please out this.
nsuserdefaults *getting= [nsuserdefaults standarduserdefaults] ; userid1=[getting objectforkey:@"uid"]; nsstring *bodystring=[nsstring stringwithformat:@"userid=%@&question=%@&categoryid=%@",userid1,asktextviewobj.text,specialistfield.text]; [bodystring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; nslog(@"%@",bodystring); request=[nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"xxxxxxxxxxxxxxxxxx" ] cachepolicy:0 timeoutinterval:30]; [request sethttpmethod:@"post"]; [request sethttpshouldhandlecookies:yes]; [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; [request sethttpbody:[bodystring datausingencoding:nsutf8stringencoding allowlossyconversion:yes]]; [request addvalue:[nsstring stringwithformat:@"%d", [bodystring length]] forhttpheaderfield:@"content-length"]; connection=[nsurlconnection connectionwithrequest:request delegate:self ]; if (!connection) { uialertview* aler = [[uialertview alloc] initwithtitle:@"network error" message:@"failed connect server " delegate:nil cancelbuttontitle:@"close" otherbuttontitles:nil]; [aler show]; } else { nslog(@"connection successfully"); }
Comments
Post a Comment