在我的 IOS 应用程序中,我需要将图像发送到 ASP.NET Web 服务。我正在尝试以字节形式处理图像,然后在服务器端将其转换回图像形式。 现在我正在使用这些行将图像转换为 IOS 中的字节:
NSData *imageData=UIImagePNGRepresentation([Mybutton currentBackgroundImage]);
这一行给出了 734,775 个字的字节,太多了,所以不能发送 soap 请求。 那么,现在我怎样才能实现这个目标呢?????
当使用 soap 请求调用服务时,它给了我这个错误:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring> System.Web.Services.Protocols.SoapException:
There was an exception running the extensions specified in the config file. ---> System.Web.HttpException: Maximum request length exceeded.
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.get_InputStream()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
我正在制作一个聊天应用程序,所以在用户注册时我必须将用户图像上传到网络服务器,当它搜索他/她周围的人时,我也想从网络服务返回 imae 我该怎么做这两件事? 首先将图像放在网络服务器上,然后从网络服务器检索。 非常感谢
最佳答案
您可以使用 JPEG 图像减少图像的内存长度 压缩
lowResolutionImage = [UIImage imageWithData:UIImageJPEGRepresentation(highResImage, quality)];
质量介于 0.0 和 1.0 之间
不要通过 Internet 将图像作为原始二进制文件发送,将二进制文件转换为 base64 字符串
because some media are made for streaming text. You never know some protocols may interpret your binary data as control characters , or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination.
Here is the link on how to convert into base64
由于您使用 IIS 托管您的应用程序,因此默认上传文件大小为 4MB。要增加它,请在您的 web.config 中使用以下部分
<configuration> <system.web> <httpRuntime maxRequestLength="1048576" /> </system.web> </configuration>
对于IIS7及以上版本,还需要添加如下几行:
<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="1073741824" /> </requestFiltering> </security>
注意:maxAllowedContentLength 以字节为单位,而 maxRequestLength 以千字节为单位,这就是此配置示例中值不同的原因。 (两者都相当于 1 GB。)
这是一个 answer另一个对你有帮助的问题
关于ios - 从 IOS 将图像发送到 asp.net web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28861220/