Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"my-url"]];
- [request setHTTPMethod:@"POST"];
- [request setValue:self.MedicalIdTxt.text forKey:@"MedicaidId"];
- [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
- NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
- if (theConnection) {
- NSLog(@"connected");
- receivedData=[[NSMutableData alloc]init];
- }
- else {
- NSLog(@"not connected");
- }
- }
- - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
- {
- [receivedData setLength:0];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- {
- [receivedData appendData:data];
- NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"response: %@",responseString);
- }
- - (void)connectionDidFinishLoading:(NSURLConnection *)connection
- {
- NSLog(@"Succeeded! Received %lu data",(unsigned long)[receivedData length]);
- NSString* responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
- NSLog(@"response: %@",responseString);
- NSError *myError = nil;
- NSDictionary *res = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableLeaves error:&myError];
- NSLog(@"final result is %@",res);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement