请求webservice接口的某方法数据

NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.com/xxx/xxxxWS?wsdl"];
    NSString *soapMsg=[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/\" xmlns:ns1=\"空间\">"
                       "<soap:Body>"
                       "<ns1:某方法>"
                       "<strUsername>%@</strUsername>"
                       "<strPassword>%@</strPassword>"
                       "<strAGName>%@</strAGName>"
                       "<OperatorName>%@</OperatorName>"
                       "<OperatorPwd>%@</OperatorPwd>"
                       "</ns1:某方法>"
                       "</soap:Body>"
                       "</soap:Envelope>", @"", @"", @"", @"", @""
                       ];
    
    NSString *space=@"空间";
    NSString *methodname=@"某方法";
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMsg length]];
    NSString *soapAction=[NSString stringWithFormat:@"%@%@",space,methodname];
    //头部设置
    NSDictionary *headField=[NSDictionary dictionaryWithObjectsAndKeys:[url host],@"Host",
                             @"text/xml; charset=utf-8",@"Content-Type",
                             msgLength,@"Content-Length",
                             soapAction,@"SOAPAction",nil];
    [request setAllHTTPHeaderFields:headField];
    //超时设置
    [request setTimeoutInterval: 30 ];
    //访问方式
    [request setHTTPMethod:@"POST"];
    //body内容
    [request setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

 

posted @ 2016-06-22 15:40  潜意识  阅读(1041)  评论(0)    收藏  举报