//返回ASIHTTPRequest对象
-(ASIHTTPRequest*)ServiceRequestUrl:(NSString*)strMethod SoapMessage:(NSString*)soapMsg{
//请求发送到的路径
NSURL * url = [NSURLURLWithString:@"http://192.168.123.132/eland/WebServices/WebService.asmx"];
//NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
ASIHTTPRequest *theRequest= [ASIHTTPRequestrequestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
//以下对请求信息添加属性前四句是必有的,第五句是soap信息。
[theRequest addRequestHeader:@"Host" value:[url host]];
[theRequest addRequestHeader:@"Content-Type"value:@"text/xml; charset=utf-8"];
[theRequest addRequestHeader:@"Content-Length" value:msgLength];
[theRequest addRequestHeader:@"SOAPAction"value:[NSStringstringWithFormat:@"http://tempuri.org/%@", strMethod]];
[theRequest setRequestMethod:@"POST"];
//传soap信息
[theRequest appendPostData:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
//[theRequest setValidatesSecureCertificate:NO];
[theRequest setTimeOutSeconds:60.0];
[theRequest setDefaultResponseEncoding:NSUTF8StringEncoding];
return theRequest;
//return theRequest;
}
//在按钮点击下执行请求
-(IBAction)buttonServiceClick:(id)sender{
NSString *soapMsg=@"<?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><GetCircular xmlns=\"http://tempuri.org/\" ><guid>07122d99-0978-46e4-aacb-3aed0ff99cb5</guid><pwd>123456</pwd><GetCircular></soap:Body></soap:Envelope>";
ASIHTTPRequest *request=[selfServiceRequestUrl:@"GetCircular"SoapMessage:soapMsg];
[request setDelegate:self];
[request startAsynchronous];//异步请求
}
//实现协议
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
NSLog(@"%@",responseString);
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"%@",[error description]);
}
===>点击按钮时,发生 怪异了,在控制台一直输出==》
错误的请求
求达人,我那里错了〜〜〜
你得statecode是多少,是不是url写错了