Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP request works in curl but not iOS or Postman
    text
    copied!<p>***I'm very new to HTTP networking.</p> <p>Basically, this works: curl -k -L -v -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header 'Authorization: OAuth someAccessToken' --header "Force-Instance-Url: websiteurl" --header "Force-User-Id: someUserId" --data "{}" "websiteurl"</p> <p>However, I can't seem to have any success getting a response in either Postman (the HTTP test plugin for chrome) or in a program I made in iOS. The results are always HTTP Status 500 - java.io.EOFException: No content to map to Object due to end of input.</p> <p>I've been very careful to make sure the urls and headers are exactly the same but no luck. In my iOS program, I have an http request that successfuly retrieves an access token, instance_url, and force_user_id. I use these fields to make the request as posted above but the response is error 500.</p> <p>Since it doesn't work in postman either I'm not sure if it helps to post my code but I will anyways:</p> <pre><code>NSURL *loginURL = [NSURL URLWithString:@"websiteurl"]; NSMutableURLRequest *request=[[NSMutableURLRequest alloc] initWithURL:loginURL]; [request setHTTPMethod:@"POST"]; NSString *instance_url = [self.loginDictionary objectForKey:@"instance_url"]; NSString *authorization = [NSString stringWithFormat:@"%@%@", @"OAuth ",[self.loginDictionary objectForKey:@"access_token"]]; NSString *instance_id = [self.loginDictionary objectForKey:@"id"]; NSRange range = [instance_id rangeOfString:@"/" options:NSBackwardsSearch]; if (range.location != NSNotFound) { instance_id = [instance_id substringFromIndex:range.location + 1]; } [request setValue:@"application/json" forHTTPHeaderField: @"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField: @"Accept"]; [request setValue:authorization forHTTPHeaderField: @"Authorization"]; [request setValue:instance_url forHTTPHeaderField: @"Force-Instance-Url"]; [request setValue:instance_id forHTTPHeaderField: @"Force-User-Id"]; NSLog(@"\n\n%@", [request allHTTPHeaderFields]); AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.loginDictionary = (NSDictionary *) JSON; NSLog(@"*************************************************************************"); NSLog(@"*************************************************************************"); NSLog(@"FIREWORKS"); } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failure Because %@",[error userInfo]); }]; [operation start]; </code></pre> <p>Here is a log print out of the request headers.</p> <pre><code>{ Accept = "application/json"; Authorization = "OAuth accessTokenValue"; "Content-Type" = "application/json"; "Force-Instance-Url" = "websiteurl"; "Force-User-Id" = someUserId; } </code></pre> <p>On a final note, the only thing that seems like a clue to me is the fact that the auth header in the curl command is in single quotes but the rest are not... I'm not sure if this is important or not. Thanks for reading and helping.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload