2

iOSを使用して、3つのヘッダーとそれに続くJSONPOSTデータを要求するWebサービスと通信しようとしています。

辞書をJSONファイルに変換する次のAFNetworkingスニペットを確認しました。この場合、ヘッダーとJSONファイルの両方をPOSTしようとしています。何か提案があれば教えてください:

NSURL *url = [NSURL URLWithString:WalletKit_URL];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFJSONParameterEncoding;
NSDictionary *params = @{@"brand-id" : Brand_Id, @"api-key" : API_Key, @"Content-Type" : @"application/json"};
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"" parameters:params];
AFHTTPRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
    NSLog(@"success");
} failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON) {
    NSLog(@"error");
}];
4

1 に答える 1

4

HTTPヘッダーフィールドをに追加する必要がありますNSMutableURLRequest

[request addValue:@"foobar" forHTTPHeaderField:@"X-Foo-Bar"];
于 2013-02-05T19:32:28.550 に答える