2012-09-07 27 views
0

我需要以XML格式創建一個NSString,所以我需要將它發送的Web服務請求。以XML格式創建的NSString作爲請求iPhone的SDK,以web服務器?

我已經創建的XML使用此代碼

NSMutableString *res = [NSMutableString string]; 

[res appendString:@"<question>"]; 
[res appendFormat:@"<productid>%@</productid>", [array objectAtIndex:0]]; 
[res appendFormat:@"<questionid>%@</questionid>", [array objectAtIndex:1]]; 
[res appendFormat:@"<valueid>%@</valueid>", [array objectAtIndex:2]]; 
[res appendFormat:@"<answerText>%@</answerText>", [array objectAtIndex:3]]; 
[res appendFormat:@"</question>"]; 

但是,結構NSString當我送這是一個請求(Web服務代碼中使用sudzc創建的),我得到了一些錯誤

Entity: line 1: parser error : Start tag expected, '<' not found 
Bad Request 
Error: The operation couldn’t be completed. (CXMLErrorDomain error 1.) 

這是我發送的字符串

NSString *send=[NSString stringWithString:@"<request><ProductName>ppr</ProductName><questionid>fff</questionid><answerText>%@</answerText></request>"]; 

什麼是所有的標籤我應該在創建字符串xml的地方?

這裏是我的要求,,

[service CreateRequest:self action:@selector(CreateRequestHandler:) Email:@"xxxx" Password:@"anoopgopalan" Token:@"xxx" Request:send]; 


    - (void) CreateRequestHandler: (id) value { 

      // Handle errors 
      if([value isKindOfClass:[NSError class]]) { 
      NSLog(@"%@", value); 
      return; 
     } 

      // Handle faults 
      if([value isKindOfClass:[SoapFault class]]) { 
      NSLog(@"%@", value); 
      return; 
    }    


       // Do something with the MFLAPIError* result 
      MFLAPIError* result = (MFLAPIError*)value; 
       NSLog(@"CreateRequest returned the value: %@", result); 

    } 
+0

你缺少一些標籤.. – vishy

+0

@vishy我不知道到底是什麼我缺少 –

+0

看到我的回答如下..這一個嘗試.. – vishy

回答

0

你缺少在導致XML字符串一些標籤..從Web服務的任何XML響應會像下面..

你的XML必須是在這種嵌入..

<?xml version="1.0" encoding="utf-8"?> 
<root> 
//your generated xml with tags 
</root> 
+0

我想這也是,,但誤差存在。我認爲這個錯誤與'<'''這些標籤有關。 :( –

+0

而且,我發送XML數據 –

+0

告訴我你的要求的代碼的NSString對象,創建請求,處理連接.. – vishy

相關問題