Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. NSData *finalData = [NSJSONSerialization dataWithJSONObject:mainDictionary options:NSJSONWritingPrettyPrinted error:nil];
  2.  
  3. //Calculate data length to post
  4. NSString *postLength = [NSString stringWithFormat:@"%d", [finalData length]];
  5.  
  6. NSString *str2 =[[NSString alloc] initWithData:finalData encoding:NSUTF8StringEncoding];
  7. NSLog(@"Final Json : %@",str2);
  8.  
  9. NSString *urlString=[NSString stringWithFormat:@"%@%@",BASE_URL,EXT_URL];
  10. NSMutableURLRequest *theRequest=[NSMutableURLRequest
  11. requestWithURL:[NSURL URLWithString:
  12. urlString]
  13. cachePolicy:NSURLRequestUseProtocolCachePolicy
  14. timeoutInterval:60.0];
  15.  
  16. [theRequest setHTTPMethod:@"POST"];
  17. [theRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  18. [theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
  19. [theRequest setHTTPBody:finalData];
  20.  
  21. [NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  22. if (error) {
  23. //do something with error
  24. } else {
  25. NSString *responseText = [[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding];
  26. NSLog(@"Response: %@", responseText);
  27.  
  28. NSString *newLineStr = @"n";
  29. responseText = [responseText stringByReplacingOccurrencesOfString:@"<br />" withString:newLineStr];
  30.  
  31. }
  32. }];
  33.  
  34. "inventoryType" : 0,
  35. "customerAddress" : "City",
  36. "customerName" : "abc",
  37. "DOJ" : "2014-09-30",
  38. "boardingPoint" : {
  39. "id" : "4",
  40. "location" : "Nothing",
  41. "time" : "06:55PM"
  42. },
  43. "PaxDetails" : [
  44. {
  45. "nameOnId" : "abc",
  46. "mobile" : "2760",
  47. "lastName" : "D",
  48. "primary" : true,
  49.  
  50. }
  51. ],
  52. "customerEmail" : "abc@gmail.com",
  53. "destinationCity" : "XYZ",
  54. "customerPhone" : "2760",
  55. "emergencyPhNumber" : "1234",
  56. "customerLastName" : "D",
  57.  
  58. }
  59.  
  60. Response: <html><head><title>JBoss Web/7.0.13.
  61. Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
  62. H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
  63. H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
  64. BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
  65. P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style>
  66. </head><body><h1>HTTP Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b>
  67. Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource () is not available.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.13.Final</h3></body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement