我正在处理一张从iphone上传到C#网络服务的图片。下面是iPhone代码
NSString *soapMessage=[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<PutImage xmlns=\"http://tempuri.org/\">\n"
"<ImgInputString>%@</ImgInputString>\n"
"</PutImage>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",imageString];
NSLog(soapMessage);
NSURL *url=[NSURL URLWithString:@"http://192.168.2.7/ImageWebService/Service1.asmx"];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:url];
NSString *msgLength=[NSString stringWithFormat:@"%d",[soapMessage length]];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/PutImage" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];但是当我访问服务器时,我收到了这个错误消息。但是,当我直接将图像字符串复制并粘贴到get服务中时,我得到了图像。它只是从iPhone中抛出了错误。
请帮帮忙
发布于 2009-12-13 07:45:24
我在这方面也遇到了问题,我相信是编码的问题,(特定于MS服务器?)这是我的建议。
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];发布于 2009-12-13 09:49:39
我把这事解决了。我已经将我的服务器端输入更改为字符串(一个bas64字符串),但我访问的web服务不是更新后的web服务,而是以前的byte[]输入。因此,我将我的web服务的dll挂在inetpub/wwwroot/bin中,指向新更改的web服务.dll。现在它就像一个护身符一样起作用。
和NWCoder,您可以将字符串加密为base64编码,并将其作为字符串发送到您的c# web服务,然后将i转换为byte[]。这对我来说很顺利。任何方式都需要你的建议。
https://stackoverflow.com/questions/1892591
复制相似问题