我想在iPhone客户端中向服务器端上传文件。
web service是axis(soap)的,相应的代码:public class FileService {
public String upload(DataHandler handler, String fileName) {
//存文件的一系列操作
}
}与之对应的wsdl片段为:<element name="upload">
<complexType>
<sequence>
<element name="handler" type="apachesoap:DataHandler"/>
<element name="fileName" type="xsd:string"/>
</sequence>
</complexType>
</element>在客户端,简单类型的参数传递是没有问题的。但是由于用apachesoap:DataHandler 接收附件(文件),在objc里始终没有找到对应的数据类型
objc代码为:(来自google)NSString *soapMessage = [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/\">"
                             "<soap:Body>\n"
                             "<ns1:upload xmlns:ns1=\"http://10.188.96.27:8080/AudioService/services/FileService?wsdl\">"
                             "<arg0>%@</arg0>"
                             "<arg1>%@</arg1>"
                             "</ns1:upload>"
                             "</soap:Body>\n"
                             "</soap:Envelope>",@"aaaadd", @"aa.txt"];
    NSLog(@"调用webserivce的字符串是:%@",soapMessage);
    //请求发送到的路径
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    NSURL *url = [NSURL URLWithString:@"http://10.188.96.27:8080/AudioService/services/FileService?wsdl"];
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
    
    //以下对请求信息添加属性前四句是必有的,
    [urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [urlRequest addValue: @"http://10.188.96.27:8080/AudioService/services/FileService?wsdl" forHTTPHeaderField:@"SOAPAction"];
    [urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    //请求
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
    theConnection = nil;请教各位,一般在ios中处理文件上传是如何操作的呢?本人新接触ios,请多指教:)