Created
November 30, 2014 17:16
-
-
Save nk-gears/f5d00ed882c781a58ab9 to your computer and use it in GitHub Desktop.
POST JSON from OBJ-C
This file contains 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
NSString *queryString = [NSString stringWithFormat:@"http://chrisrisner.com/Labs/day7test.php?name=%@", [self.txtName text]]; | |
NSMutableURLRequest *theRequest=[NSMutableURLRequest | |
requestWithURL:[NSURL URLWithString: | |
queryString] | |
cachePolicy:NSURLRequestUseProtocolCachePolicy | |
timeoutInterval:60.0]; | |
NSDictionary* jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys: | |
@"Value1", @"Key1", | |
@"Value2", @"Key2", | |
nil]; | |
NSError *error; | |
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary | |
options:NSJSONWritingPrettyPrinted error:&error]; | |
[theRequest setHTTPMethod:@"POST"]; | |
[theRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
// should check for and handle errors here but we aren't | |
[theRequest setHTTPBody:jsonData]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ref : http://chrisrisner.com/31-Days-of-iOS--Day-8%E2%80%93Performing-Posts-and-setting-request-type