***私は HTTP ネットワーキングに非常に慣れていません。
基本的に、これは機能します: 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"
ただし、Postman (Chrome 用の HTTP テスト プラグイン) または iOS で作成したプログラムで応答を取得することに成功していないようです。結果は常に HTTP ステータス 500 - java.io.EOFException: No content to map due to end of input です。
URL とヘッダーがまったく同じであることを確認するために細心の注意を払ってきましたが、うまくいきませんでした。私の iOS プログラムには、アクセス トークン、instance_url、および force_user_id を正常に取得する http 要求があります。上記のようにこれらのフィールドを使用してリクエストを作成しましたが、応答はエラー 500 です。
郵便配達員でも機能しないため、コードを投稿するのに役立つかどうかはわかりませんが、とにかく:
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];
以下は、リクエスト ヘッダーのログ出力です。
{
Accept = "application/json";
Authorization = "OAuth accessTokenValue";
"Content-Type" = "application/json";
"Force-Instance-Url" = "websiteurl";
"Force-User-Id" = someUserId;
}
最後に、私にとって手がかりのように思える唯一のことは、curl コマンドの認証ヘッダーが一重引用符で囲まれているという事実ですが、残りはそうではありません...これが重要かどうかはわかりません。読んで助けてくれてありがとう。