我正在尝试将图像从 iphone 应用程序发布到 .Net 网络服务,但我遇到了这个错误。我已经根据 this kb article 更新了我的 web.config并且我可以成功发布到将字符串作为参数的方法。我的问题是试图发布带有图像的数据。我试过发布 this way和 that 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/