2011-12-23 30 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

相关问题