Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AFNetworking AFMultipartFormData如何设置密钥_Iphone_Objective C_Ios_Afnetworking - Fatal编程技术网

Iphone AFNetworking AFMultipartFormData如何设置密钥

Iphone AFNetworking AFMultipartFormData如何设置密钥,iphone,objective-c,ios,afnetworking,Iphone,Objective C,Ios,Afnetworking,我想像以前一样用setkey“FileData”上传(发布)图像到服务器(使用ASIHTTPRequest编写,可以正常工作) 使用AFN网络,我设置如下: NSMutableURLRequest *afRequest = [httpClient multipartFormRequestWithMethod:@"POST" path:@"" parameters:paramsDic constructingBodyWithBlock: ^(id <AFMultipartFormData&g

我想像以前一样用setkey“FileData”上传(发布)图像到服务器(使用ASIHTTPRequest编写,可以正常工作)

使用AFN网络,我设置如下:

NSMutableURLRequest *afRequest = [httpClient multipartFormRequestWithMethod:@"POST" path:@"" parameters:paramsDic constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
        [formData appendPartWithFileData:imageData name:@"Filedata" fileName:dateFormatted mimeType:@"image/jpeg"];
    }];
NSMutableURLRequest*afRequest=[httpClient multipartFormRequestWithMethod:@“POST”路径:@”参数:paramsDic constructingBodyWithBlock:^(id formData){
[formData appendPartWithFileData:imageData名称:@“Filedata”文件名:dateFormatted mimeType:@“image/jpeg”];
}];
似乎这个名字实际上不起作用。。。 我该如何设置钥匙@马特


谢谢

您好,我正在上传音频/图像文件,如下所示。请使用ASIHTTPRequest检查音频/图像文件及其工作状况

NSURL *audiourl = [NSURL URLWithString:@"Your Url"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:audiourl];
NSData *postData = [NSData dataWithContentsOfURL:SoundPath];
//SoundPath is your audio url path of NSDocumentDirectory.
[request addData:postData withFileName:@"mynewfile.png" andContentType:@"image/png"   forKey:@"FileData"];
[request setDelegate:self];
[request startasynchronous];

谢谢

我想出来了,问题是我加了这一行

[afRequest setValue:@"application/x-www-form-urlencoded; charset=UTF8" forHTTPHeaderField:@"Content-Type"];
但我仍然不知道为什么,我将这一行添加到其他http请求中,它可以工作,但是文件上传。我检查了服务器,当用这行做文件上传时,服务器收到了很多。。。陛下想一想如何描述它,群信……如下:

NSMutableURLRequest *afRequest = [httpClient multipartFormRequestWithMethod:@"POST" path:@"" parameters:paramsDic constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
        [formData appendPartWithFileData:imageData name:@"Filedata" fileName:dateFormatted mimeType:@"image/jpeg"];
    }];
内容类型:图像/jpeg^M^M ÿ^@^@^@


谢谢,但正如我所说,我以前用过ASIHTTPRequest,现在我正在做从ASIHTTPRequest到AFNetworking的转换,我可以用ASIHTTPRequest上传,但是AFNetworking。。。因为“福克斯”。服务器无法使用AFNetworking获取该字段。。。