Ios5 如何上传图像+;使用iphone应用程序的SOAP请求将xml转换为web服务器

Ios5 如何上传图像+;使用iphone应用程序的SOAP请求将xml转换为web服务器,ios5,soap,uiimage,nsdata,Ios5,Soap,Uiimage,Nsdata,我正在实现一个iPad应用程序。在我的应用程序中,我需要从用户那里获取一些信息和配置文件pic,并需要使用SOAP请求将这些信息上传到web服务器。我完成了文本输入上传。但说到形象,我却没有意识到这一点。我知道,要上传图像,我们需要将其转换为NSData,我做到了,但如何将其添加到我的帖子字符串中 我的代码如下: NSData* imageData = UIImagePNGRepresentation(myPic); NSString* uploadValues=@""; uploadValue

我正在实现一个iPad应用程序。在我的应用程序中,我需要从用户那里获取一些信息和配置文件pic,并需要使用SOAP请求将这些信息上传到web服务器。我完成了文本输入上传。但说到形象,我却没有意识到这一点。我知道,要上传图像,我们需要将其转换为NSData,我做到了,但如何将其添加到我的帖子字符串中

我的代码如下:

NSData* imageData = UIImagePNGRepresentation(myPic);
NSString* uploadValues=@"";
uploadValues = [uploadValues stringByAppendingString:[NSString stringWithFormat:@"<UserInformation><UserInfo action=\"INSERT\"><Userid>123</Userid><FirstName>abc</FirstName><LastName>xyz</LastName><Contact>00000000</Contact><Email>abc@googole.com</Email><Address>USA</Address><Image>How can I put image data here? is that work if I put data here?</Image></UserInfo></UserInformation>"];
        uploadValues = [uploadValues stringByReplacingOccurrencesOfString:@"(null)" withString:@" "];
        serverConnections=[ServerConnections sharedConnections];
        serverConnections.delegate=self;

        NSString* soapString = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?> \n"
                                "<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"
                                "<SetUserInfo xmlns=\"http://example.com/\">\n"
                                "<Data><![CDATA[ %s ]]></Data> \n"
                                "</SetUserInfo> \n"
                                "</soap:Body>\n"
                                "</soap:Envelope>\n",[uploadValues UTF8String]];

        printf("\n Input string:%s",[soapString UTF8String]);


        NSURL *url = [NSURL URLWithString:@"http://example.com/xyz.asmx"];
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapString length]];

        [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue: @"http:/example.com/SetUserInfo" forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody: [soapString dataUsingEncoding:NSUTF8StringEncoding]];
        [serverConnections startEstablishingConnectionwithServer:theRequest];
NSData*imageData=UIImagePNGRepresentation(myPic);
NSString*上传值=@“”;
uploadValues=[uploadValues stringByAppendingString:[NSString stringWithFormat:@]123abcxyz00000000abc@googole.comUSAHow我可以把图像数据放在这里吗?如果我把数据放在这里,这样行吗;
uploadValues=[uploadValues stringByReplacingOccurrencesOfString:@“(null)”和字符串:@”“;
serverConnections=[serverConnections sharedConnections];
serverConnections.delegate=self;
NSString*soapString=[NSString stringWithFormat:@“\n”
“\n”
“\n”
“\n”
“\n”
“\n”
“\n”
“\n”,[uploadValues UTF8String]];
printf(“\n输入字符串:%s,[soapString UTF8String]);
NSURL*url=[NSURL URLWithString:@”http://example.com/xyz.asmx"];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapString length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[TheRequestAddValue:@“http:/example.com/SetUserInfo”用于HttpHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapString数据使用编码:NSUTF8StringEncoding];
[服务器连接开始测试与服务器的连接:请求];
来自


我会这样做,但从服务器端他们如何访问这些图像数据
 [req addValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
 [req setHTTPBody:imgData]