我使用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