HTTP GET in JSON within an API -
how http request of data in json format, 1 api endpoint , post api endpoint.
-(void)getrequest{
//init nsurlsession configuration nsurlsessionconfiguration *defaultconfigobject = [nsurlsessionconfiguration defaultsessionconfiguration]; nsurlsession *defaultsession = [nsurlsession sessionwithconfiguration: defaultconfigobject delegate: nil delegatequeue: [nsoperationqueue mainqueue]]; //create urlrequest nsurl *url = [nsurl urlwithstring:@"your url"]; nsmutableurlrequest *urlrequest = [nsmutableurlrequest requestwithurl:url]; [urlrequest sethttpmethod:@"get"]; [urlrequest setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; //create task nsurlsessiondatatask *datatask = [defaultsession datataskwithrequest:urlrequest completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { //handle response here // nslog(@"resultsdictionary %@",response); }]; [datatask resume];
}
Comments
Post a Comment