上载到.NET web服务iOS
我需要传递一些数据,以便服务器保存信息,为此,参数需要在url后面的XML节点中传递参数 下面是XML节点结构的一个示例上载到.NET web服务iOS,ios,xml,web-services,wcf,get,Ios,Xml,Web Services,Wcf,Get,我需要传递一些数据,以便服务器保存信息,为此,参数需要在url后面的XML节点中传递参数 下面是XML节点结构的一个示例 <Send_info> <Service_order> </Service_order> <Data_stream> <info> </info> </Data_stream> </Send_info>. 编辑:您可以在注释中找到答案,答案非常简单,只需使用这些代码块
<Send_info>
<Service_order>
</Service_order>
<Data_stream>
<info>
</info>
</Data_stream>
</Send_info>.
编辑:您可以在注释中找到答案,答案非常简单,只需使用这些代码块并用您自己的参数替换它们 职位: 获取:
-(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];
}
-(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
}