ios - How to use HTTP POST on Xcode -
sorry, beginner question here.i trying use http post retrieve xml document url, , there parameters need include in post request.i have got code this website in objective c section , starting understand it. need try , use class in app. here parameters need include:
url: https://admin.poslavu.com/cp/reqserv/ dataname=tangere_techno&key=dbkey&token=dbt0ken&table=menu_groups

try:
nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"https://admin.poslavu.com/cp/reqserv/"]]; [request setvalue:@"gzip" forhttpheaderfield:@"accept-encoding"]; [request sethttpbody:[[nsstring stringwithformat:@"dataname=tangere_techno&key=dbkey&token=dbt0ken&table=menu_groups"] datausingencoding:nsutf8stringencoding]]; [request sethttpmethod:@"post"]; nserror *error = nil; nsurlresponse *response = nil; nsdata *data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; if (error) { nslog(@"error:%@", error.localizeddescription); } else { //success }
data should xml info, you'll need parse first though. should try looking @ apple's docs more information. if trying make request asynchronously try this:
nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"https://admin.poslavu.com/cp/reqserv/"]]; [request setvalue:@"gzip" forhttpheaderfield:@"accept-encoding"]; [request sethttpbody:[[nsstring stringwithformat:@"dataname=tangere_techno&key=dbkey&token=dbt0ken&table=menu_groups"] datausingencoding:nsutf8stringencoding]]; [request sethttpmethod:@"post"]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:req]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject){ nsdata *data = (nsdata *)responseobject; } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }]; [operation start];
Comments
Post a Comment