2011-12-23 62 views
0

我使用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,因爲我不知道任何事情的代碼。

+0

ASIHTTPRequest不會爲你創建SOAP數據,你仍然需要自己做,同樣與NSURLConnection的。如果您發佈了工作NSURLConnection代碼,我們可以告訴您如何使用ASIHTTPRequest編寫相同的代碼。 – JosephH 2011-12-23 11:37:21

+0

@JosephH,更新了我的問題。 – Heena 2011-12-26 04:37:10

+0

如果我們需要創建肥皂消息,那麼使用NSURLConnection和ASIHttpRequest有什麼區別?在這種情況下,我們如何使用ASIFormDataRequest的setPostValue方法? – Heena 2011-12-26 06:22:43

回答

0

使用ASIHTTPRequest時,您需要以與NSURLConnection基本相同的方式創建SOAP請求。

setPostValue呼叫ASIHTTPRequest是建立在相同的格式使用了HTML中的POST <form>標籤HTTP POST請求。

爲了比較ASIHTTPRequest/NSURLConnection的,看到喜歡的東西: 「什麼是ASIHTTPRequest」

ASIHTTPRequest vs NSURLConnection

和於:

http://allseeing-i.com/ASIHTTPRequest/

+0

我已經通過相同的鏈接http://allseeing-i.com/ASIHTTPRequest/,但沒有任何創建SOAP消息的規範 – Heena 2012-01-02 04:15:54

+0

ASIHTTPRequest沒有對SOAP的明確支持 - 你只需要按照與NSURLConnection的。即。創建一個POST請求,將你的SOAP xml設置爲body,並將Content-Type設置爲text/xml。 – JosephH 2012-01-02 10:22:49

相關問題