我使用NSURLConnection与Soap webservice进行通信,效果很好。
现在我正在使用ASIFormDataRequest并且我没有得到是否有必要为此创建soap消息?我不知道什么是SoapAction。
以下是我正在使用的代码
NSURL *url = [NSURL URLWithString:@"http://SERVERNAME.com/WEBSERVICENAME"];
[self setFrmdataReq:[ASIFormDataRequest requestWithURL:url]];
[frmdataReq setRequestMethod:@"POST"];
[frmdataReq addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
[frmdataReq setPostValue:txtField.text forKey:@"city"];
[frmdataReq setDelegate:self];
[frmdataReq setDidFinishSelector:@selector(requestFinished:)];
[frmdataReq setDidFailSelector:@selector(requestFailed:)];
[frmdataReq startSynchronous];
更新
我用的肥皂消息,
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\
<soap12:Body>\
<getCityTime xmlns=\"http://www.Nanonull.com/TimeService/\">\
<city>%@</city>\
</getCityTime>\
</soap12:Body>\
</soap12:Envelope>",txtField.text];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn)
{
responseData = [[NSMutableData data]retain];
NSLog(@"connection successful");
}
else
NSLog(@"connection fail.");
我没有定义SOAPAction,因为我对此一无所知。
答案 0 :(得分:0)
使用ASIHTTPRequest时,您需要以与使用NSURLConnection基本相同的方式创建SOAP请求。
ASIHTTPRequest中的setPostValue
调用用于创建HTTP POST请求,其格式与HTML中的POST <form>
标记的格式相同。
要比较ASIHTTPRequest / NSURLConnection,请参阅:
ASIHTTPRequest vs NSURLConnection
和“什么是ASIHTTPRequest?”于: