.net - 'System.InvalidOperationException : Request format is invalid: multipart/form-data' error when posting image from iphone to . NET 网络服务

标签 .net objective-c web-services file-upload

我正在尝试将图像从 iphone 应用程序发布到 .Net 网络服务,但我遇到了这个错误。我已经根据 this kb article 更新了我的 web.config并且我可以成功发布到将字符串作为参数的方法。我的问题是试图发布带有图像的数据。我试过发布 this waythat way , 但两种方式我都遇到了同样的错误:

System.InvalidOperationException: Request format is invalid: multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY. at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

这是我的网络服务签名:


[WebMethod]
public XmlDocument UploadImageToServer(string usertoken, byte[] image)
{ 
   //stuff happens in here
}

..这是我最近的尝试:


- (void)sendImageToServer:(NSURL *)serivceURL withUserToken:(NSString *)usertoken
{
 NSData *imageData = UIImageJPEGRepresentation(self.selectedImage, 1.0f);

 ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:serviceURL] autorelease];
 [request setPostValue:usertoken forKey:@"usertoken"];
 [request setData:imageData forKey:@"image"];
 [request setDelegate:self];
 [request startAsynchronous];

 NSLog(@"We set the request out!");

}

此外,我将我的 httpRuntime 最大请求长度增加到 40MB ( <httpRuntime maxRequestLength="40960"/> ) 只是为了确保问题不是我的图像大小,但错误仍然存​​在。

如有任何帮助,我们将不胜感激。

最佳答案

我通过将这些移动到 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.webServer><handlers> 的底部部分在 web.config 中,但由于我将它们移到了顶部,它似乎可以工作!

关于.net - 'System.InvalidOperationException : Request format is invalid: multipart/form-data' error when posting image from iphone to . NET 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2067742/

相关文章:

C# 相当于 adodb 记录集

c# - 使用反射时如何调用方法?

c# - 在 Mono Android (Xamarin.Android) 中创建 .NET 等效颜色静态类

objective-c - 如何在iOS中从 block 中获取变量

java - JSON解析异常 : Expected BEGIN_ARRAY but was BEGIN_OBJECT?

c# - 静态构造函数和 BeforeFieldInit?

iphone - 在 DrawRect 方法中收到内存警告

objective-c - KVO for one-to-many but NSNull object passed into observeValueForKeyPath

python - 如何加速 Python 中的网络爬行?

jquery - 如何删除 d : from json response through c#?