Guest User

Untitled

a guest
Jan 4th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. NSString *roomnumber = (NSString *)[newPatient objectForKey:@"roomNumber"];
  2.  
  3. NSString *urlString = [NSString stringWithFormat:@"http//norkelton.com/room/%d",roomnumber];
  4.  
  5. // NSString *encodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  6.  
  7.  
  8.  
  9. NSURL *theURL = [NSURL URLWithString:urlString];
  10.  
  11.  
  12.  
  13. //request
  14.  
  15. NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL];// cachePolicy:
  16.  
  17. [theRequest setHTTPMethod:@"POST"];
  18.  
  19. [theRequest setHTTPShouldHandleCookies:YES];
  20.  
  21.  
  22.  
  23. //cookies
  24.  
  25. NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:[[Cookies sharedCookies] cookies]];
  26.  
  27. [theRequest setAllHTTPHeaderFields:headers];
  28.  
  29.  
  30.  
  31. //body of request
  32.  
  33. NSString *bodyString = newPatient.JSONRepresentation;
  34.  
  35. NSData *bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
  36.  
  37. [theRequest setHTTPBody:bodyData];
  38.  
  39.  
  40.  
  41. NSHTTPURLResponse *response;
  42.  
  43.  
  44.  
  45. //NSError *theError = NULL;
  46.  
  47. NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:nil];
  48.  
  49. NSLog(@"status code: %d\n",[response statusCode]);
  50.  
  51.  
  52.  
  53. NSLog(@"RESPONSE HEADERS: \n%@", [response allHeaderFields]);
  54.  
  55. NSString *theResponseString = [[[NSString alloc] initWithData:theResponseData encoding:NSUTF8StringEncoding] autorelease];
  56.  
  57. NSLog(@"******************************------------------%@\n",theResponseString);
Add Comment
Please, Sign In to add comment