Created
August 5, 2014 17:09
-
-
Save rvill/486bf13d6514dc830904 to your computer and use it in GitHub Desktop.
Set HTTP headers in objective c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 some default parameter(like content-type etc.) | |
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | |
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; | |
//Now pass your own parameter | |
[theRequest setValue:yourValue forHTTPHeaderField:theNameOfThePropertyValue]; | |
NSURLResponse *theResponse = NULL; | |
NSError *theError = NULL; | |
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError]; | |
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:theResponseData options:0 error:&theError]; | |
NSLog(@"url to send request= %@",theURL); | |
NSLog(@"%@",dataDictionaryResponse); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment