AFNetworking HTTP POST成功空

时间:2015-10-23 18:41:20

标签: ios iphone afnetworking ios9 afnetworking-2

我需要发出HTTP POST请求,在该请求中我必须发送一些文本字段和几个文件。 每次我发出请求时,都会上传文件,但我会得到这样的回复。 “成功:< 656d7074 79>” (又名“空”)

这是代码,我的参数字典是。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
AFHTTPRequestOperation *operation = [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    // Append Files
    NSError *error;
    for (NSString *filePathsKey in filesPathsDictionary) {
        [formData appendPartWithFileURL:[NSURL fileURLWithPath:filesPathsDictionary[filePathsKey]] name:filePathsKey error:&error];
        if (error) {
            NSLog(@"%@", error);
        }
    }

    // Text parameters
    for (NSString *textParameterKey in textParamDictionary) {
        [formData appendPartWithFormData:[textParamDictionary[textParameterKey] dataUsingEncoding:NSUTF8StringEncoding] name:textParameterKey];
    }

} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

[operation start];

更新: 将我的响应序列化程序更改为JSON,因为我期待JSON manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

收到此错误: Error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

0 个答案:

没有答案