0

我正在关注一些通过 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;
}
4

1 回答 1

2

嗨,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' 将图像从 iphone 发布到 .NET webservice 时出错

于 2013-04-10T10:05:55.043 回答