2015-03-02 44 views
0

我需要爲了傳遞一些數據,服務器到存儲的信息,爲了做到這一點的參數需要傳遞XML節點參數如下的URL http://xxx.xxx.xx.xxx/WCF/Service1.svc/XXX/Upload?sXML=上傳到.NET Web服務的iOS

下面是XML節點結構

<Send_info> 
<Service_order> 
</Service_order> 
<Data_stream> 
<info> 
</info> 
</Data_stream> 
</Send_info>. 

返回值將是一個JSON字符串與{「上傳」:「TRUE」}的一例{:「FALSE」,「上載」}分別或。

我試過這個方法沒有回答它只是返回零。

-(void)Request:(NSData*)data{ 
NSURL *aUrl = [NSURL  URLWithString:@"http://xxx.xxx.xx.xxx/WCF/Service1.svc/XXX/Upload?sXML="]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl 
                 cachePolicy:NSURLRequestUseProtocolCachePolicy 
                timeoutInterval:60.0]; 
[request setHTTPMethod:@"GET"]; 

[request setHTTPBody:data]; 

NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request               delegate:self]; 
[connection start]; 
} 

編輯:您可以找到答案的評論

回答

0

答案只是使用這些代碼塊,並用自己的參數代替它們很簡單

POST:

-(void)webservicepost:(NSString *)poststring{ 

NSString *poststring = @"String in the format we need to upload"; 

NSURL *remoteURL = [NSURL URLWithString:@"URL in which we'll upload"]; 

NSMutableURLRequest *Request = [[NSMutableURLRequest alloc] initWithURL:remoteURL]; 

[Request addValue:@"application/json; charset=utf-8" forHTTPHeaderField: @"Content-Type"];//Formats for the data 

NSMutableData *body = [NSMutableData data]; 

[body appendData:[poststring dataUsingEncoding:NSUTF8StringEncoding]]; //Add content and coding 

[Request setHTTPMethod:@"POST"]; //POST method 

[Request setHTTPBody:body]; 

NSData *data = [NSURLConnection sendSynchronousRequest:Request returningResponse:nil error:nil];//Server response in data form 

NSString *sdata = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];//Server response in string form 

} 

GET:

-(void)get:(NSString *)myxmlstring{ 
NSString *escapedString = [myxmlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSString *urlString = [NSString stringWithFormat:@"http://xxx.xxx.xx.xxx/WCF/Service1.svc/XXX/Upload?sXML=%@",escapedString]; 
NSURL *url = [NSURL URLWithString:urlString]; 

    NSData *data = [NSURLConnection sendSynchronousRequest:Request returningResponse:nil error:nil];//Server response in data form 

NSString *sdata = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];//Server response in string form 

//FROM HERE YOU CAN USE THE RETRIEVED INFORMATION FROM THE URL 

}