Guest User

Untitled

a guest
Aug 3rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. Json Request in iphone
  2. NSString *postStr = [NSString stringWithFormat:@"username=%@&password=%@", username, password];
  3. NSData *postData = [postStr dataUsingEncoding:NSUTF8StringEncoding];
  4. NSMutableURLRequest *requesting = [[NSMutableURLRequest alloc] initWithURL:YourURLObject];
  5. [requesting setHTTPMethod:@"POST"];
  6. [requesting setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
  7. [requesting setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  8. [requesting setHTTPBody:postData];
  9. NSError *error;
  10. NSHTTPURLResponse *response;
  11. [NSURLConnection sendSynchronousRequest:requesting returningResponse:&response error:&error];
  12.  
  13. NSArray *credentials = [NSArray arrayWithObjects:@"uName", @"pWord",nil];
  14. NSString *jsonString = [credentials JSONString];
  15.  
  16. NSDictionary *credentials = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"uName", @"pWord",nil] forKeys:[NSArray arrayWithObjects:@"UserName",@"password",nil]];
  17. NSString *jsonString = [credentials JSONString];
Add Comment
Please, Sign In to add comment