iphone - 获取 System.InvalidOperationException : Request format is invalid: multipart/form-data error while upload image(data) via AFNetworking

标签 iphone .net ios web-services afnetworking

我正在学习一些通过 AFNetworking 上传图像(数据)的教程。我已经做了

 NSURL *url = [NSURL URLWithString:@"http://184.154.0.24"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

//    NSMutableDictionary* _params = [[NSMutableDictionary alloc] init];
//    [_params setObject:multiMData forKey:@"Bytes"];
//    [_params setObject:name forKey:@"UserId"];
//    [_params setObject:@"Hello" forKey:@"fileName"];
//    [_params setObject:@"png" forKey:@"contentType"];

//    [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];

NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/IphoneVideoService/webservice.asmx/getStringData" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
    [formData appendPartWithFileData:multiMData name:@"stringReturn" fileName:@"stringReturn.png" mimeType:@"image/png"];
}];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];


[operation setCompletionBlock:^{
    NSLog(@"%@", operation.responseString); //Lets us know the result including failures
}];

//    NSOperationQueue *queue = [[NSOperationQueue alloc] init] ;
//    [queue addOperation:operation];

[httpClient enqueueHTTPRequestOperation:operation];

编译后报错

2013-04-09 13:22:49.153 Softo Chat[582:19d03] Sent 323584 of 333526 bytes
2013-04-09 13:22:49.153 Softo Chat[582:19d03] Sent 327680 of 333526 bytes
2013-04-09 13:22:49.153 Softo Chat[582:19d03] Sent 331776 of 333526 bytes
2013-04-09 13:22:49.154 Softo Chat[582:19d03] Sent 333526 of 333526 bytes
2013-04-09 13:22:49.154 Softo Chat[582:1ad0b] System.InvalidOperationException: Request    format is invalid: multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY.
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

及其服务器端编程asp.net

[WebMethod]
public string getStringData(string stringReturn)
{
    return stringReturn;
}

最佳答案

嗨,Pravi jay,我刚刚用谷歌搜索了一下,得到了一个与你相关的好问题。您只需要对 web.config 进行一些更改。

<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

请访问:-

'System.InvalidOperationException: Request format is invalid: multipart/form-data' error when posting image from iphone to .NET webservice

关于iphone - 获取 System.InvalidOperationException : Request format is invalid: multipart/form-data error while upload image(data) via AFNetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15896556/

相关文章:

javascript - 当到达下拉列表时点击 iphone 手机箭头键,它应该显示下拉列表内容

iphone - UITableViewCell 内的 UIWebView 闪烁白色并且大小不正确

iphone - PhoneGap/iPhone/zxing

c# - 'this'在C#语言中有什么用?

.net - 检测 C#/.NET 中后台进程的结束?

c# - 如何将 ListView 的多个选定项目复制到剪贴板?

iphone - 有没有像scrollviewDidScroll这样的uipickerview委托(delegate)方法?

ios - 如何隐藏SFSafariViewController?

ios - 实时更新 UITableViewCell 中的 UILabel

iOS 应用程序 - 非公共(public) API 使用 - 应用程序引用非公共(public)选择器 : cancelButtonClicked, setResult: