【问题标题】:Upload to .NET web service iOS上传到 .NET Web 服务 iOS
【发布时间】:2015-03-02 05:14:21
【问题描述】:

我需要传递一些数据以便服务器保存信息,为了做到这一点,参数需要传递 XML 节点中的参数,跟随 url http://xxx.xxx.xx.xxx/WCF/Service1.svc/XXX/Upload?sXML=

这里是一个 XML 节点结构的例子

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

返回值将是一个 JSON 字符串,分别带有 {"Uploaded":"TRUE"} 或 {"Uploaded":"FALSE"}。

我试过这个方法没有答案,它只是返回 nil。

-(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];
}

编辑:你可以在 cmets 中找到答案

【问题讨论】:

    标签: ios xml web-services wcf get


    【解决方案1】:

    答案很简单,只需使用这些代码块并用您自己的参数替换它们

    发布:

     -(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
    
    }
    

    获取:

    -(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
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      相关资源
      最近更新 更多