Created
October 20, 2012 01:44
-
-
Save ChrisRisner/3921647 to your computer and use it in GitHub Desktop.
iOS Day 8
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
- (IBAction)btnFetchData1:(id)sender { | |
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]; | |
[theRequest setHTTPMethod:@"POST"]; | |
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; | |
if (con) { | |
_receivedData=[NSMutableData data]; | |
} else { | |
//something bad happened | |
} | |
} |
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
[theRequest setHTTPMethod:@"POST"]; | |
NSString *post = [NSString stringWithFormat:@"postedValue=%@", [self.txtName text]]; | |
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding]; | |
[theRequest setHTTPBody:postData]; |
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
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