iOS请求webservice(转)
2012-07-23 16:01
183 查看
(IBAction) webServicexRequestPost:(id)sender{
//封装soap请求消息,构建webServices请求字符串
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//">/n"
"<soap:Body>/n"
"<Test xmlns=/"http://jinlong.ctc.com/">/n"
"<userID>%@</userID>/n"
"</Test>/n"
"</soap:Body>/n"
"</soap:Envelope>/n",@"JINLONG"
];
NSString * msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
//设置请求地址
NSURL * url = [NSURL URLWithString:@"http://localhost:8080/TestWebServices/services/Test"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
//加请求头文件
[urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue: @"http://service.xiva.com/login" forHTTPHeaderField:@"SOAPAction"];
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
//设置请求方式
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *reponse;
NSError * error = nil;
//接受返回数据
NSData * responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&reponse error:&error];
NSMutableString *
result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Return String is========>%@",result);
}
//封装soap请求消息,构建webServices请求字符串
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//">/n"
"<soap:Body>/n"
"<Test xmlns=/"http://jinlong.ctc.com/">/n"
"<userID>%@</userID>/n"
"</Test>/n"
"</soap:Body>/n"
"</soap:Envelope>/n",@"JINLONG"
];
NSString * msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
//设置请求地址
NSURL * url = [NSURL URLWithString:@"http://localhost:8080/TestWebServices/services/Test"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
//加请求头文件
[urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue: @"http://service.xiva.com/login" forHTTPHeaderField:@"SOAPAction"];
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
//设置请求方式
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *reponse;
NSError * error = nil;
//接受返回数据
NSData * responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&reponse error:&error];
NSMutableString *
result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Return String is========>%@",result);
}
相关文章推荐
- IOS:SOAP(Webservice)请求基于AFN2.6之后
- iOS请求webservice
- iOS - AFNetworking3.0 发送SOAP请求到Webservice
- IOS请求WebService/WCF服务的方法
- iOS请求webservice
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- IOS 使用Http模拟SOAP请求Webservice时内容Unicode编码的实现
- iOS WebService Soap 请求遇到服务器400错误
- iOS 使用ASIHTTPRequest 发送Webservice请求
- iOS WebService SOAP 请求的实现
- iOS iPhone通过get和post方式请求asp.net webservice
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- IOS -- 基于WebService WSDL 的请求
- iOS网络开发-AFNetworking请求asp.net WebService
- iOS从webservice上请求数据,第一次接触怎么搞?
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- IOS UIWebView请求https站点及html页面内部ajax请求 对https的支持
- iOS---iOS开发零基础教程之AFNetWorking POST 队列请求