我使用NSURLConnection与Soap webservice进行通信,它工作正常。使用ASIFormDataRequest/ASIHTTPRequest时是否需要创建soap消息?
现在我使用ASIFormDataRequest,我没有得到是否有必要为此创建肥皂消息?我不知道什么是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];
UPDATE
SOAP消息,
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,因为我不知道任何事情的代码。
ASIHTTPRequest不会为你创建SOAP数据,你仍然需要自己做,同样与NSURLConnection的。如果您发布了工作NSURLConnection代码,我们可以告诉您如何使用ASIHTTPRequest编写相同的代码。 – JosephH 2011-12-23 11:37:21
@JosephH,更新了我的问题。 – Heena 2011-12-26 04:37:10
如果我们需要创建肥皂消息,那么使用NSURLConnection和ASIHttpRequest有什么区别?在这种情况下,我们如何使用ASIFormDataRequest的setPostValue方法? – Heena 2011-12-26 06:22:43