Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. - (void)viewDidLoad {
  2.  
  3. [super viewDidLoad];
  4.  
  5. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"my-url"]];
  6.  
  7. [request setHTTPMethod:@"POST"];
  8.  
  9. [request setValue:self.MedicalIdTxt.text forKey:@"MedicaidId"];
  10.  
  11. [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  12.  
  13. NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
  14.  
  15. if (theConnection) {
  16. NSLog(@"connected");
  17.  
  18. receivedData=[[NSMutableData alloc]init];
  19. }
  20. else {
  21.  
  22. NSLog(@"not connected");
  23. }
  24. }
  25.  
  26. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  27. {
  28. [receivedData setLength:0];
  29. }
  30.  
  31. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  32. {
  33. [receivedData appendData:data];
  34. NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  35. NSLog(@"response: %@",responseString);
  36. }
  37.  
  38. - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  39. {
  40. NSLog(@"Succeeded! Received %lu data",(unsigned long)[receivedData length]);
  41.  
  42. NSString* responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
  43.  
  44. NSLog(@"response: %@",responseString);
  45.  
  46. NSError *myError = nil;
  47.  
  48. NSDictionary *res = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableLeaves error:&myError];
  49.  
  50. NSLog(@"final result is %@",res);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement