ios - Fields to be set in HTTP header -


i calling web service in ios. this, need set header in nsmutableurlrequest object. service takes 2 string parameters , returns data in json format. the fields need set in header (both while using get , post) using setvalue:forhttpheaderfield:.

we not need use sethttpbody: while using get.. right???

i had same question , resolved (using code iducool , ankit mehta) this...

nsurl *theurl = [nsurl urlwithstring:@"yoururl"]; nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:theurl      cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:20.0f];  //specify method of request(get or post) [therequest sethttpmethod:@"get"];  //pass default parameter(like content-type etc.) [therequest setvalue:@"application/json" forhttpheaderfield:@"accept"]; [therequest setvalue:@"application/json; charset=utf-8" forhttpheaderfield:@"content-type"];  //now pass own parameter  [therequest setvalue:yourvalue forhttpheaderfield:thenameofthepropertyvalue];  nsurlresponse *theresponse = null; nserror *theerror = null; nsdata *theresponsedata = [nsurlconnection sendsynchronousrequest:therequest returningresponse:&theresponse error:&theerror];  //now can create nsdictionary nsjsonserialization nsdictionary *datadictionaryresponse = [nsjsonserialization jsonobjectwithdata:theresponsedata options:0 error:&theerror]; nslog(@"url send request= %@",theurl);      nslog(@"%@",datadictionaryresponse); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -