Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  2. [dictionary setValue:@1 forKey:@"driverId"];
  3. [dictionary setValue:@1 forKey:@"busId"];
  4. [dictionary setValue:@1 forKey:@"lineId"];
  5.  
  6. NSData *postData = nil;
  7. NSString *requestData = @"";
  8. NSString *urlPath = @"myurl";
  9. if([NSJSONSerialization isValidJSONObject:dictionary]){
  10. postData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
  11. NSString *str = [[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding];
  12. requestData = [requestData stringByAppendingString:str];
  13.  
  14. postData = [NSData dataWithBytes:[requestData UTF8String] length:[requestData length]];
  15. }
  16.  
  17. NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
  18. NSURL *url = [NSURL URLWithString:urlPath];
  19.  
  20. NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
  21. [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  22. [request setHTTPMethod:@"POST"];
  23. [request setHTTPBody:postData];
  24.  
  25. NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  26. NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  27.  
  28. NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
  29. NSString *status = [responseDic objectForKey:@"status"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement