简体   繁体   English

如何使用RESTFul Web服务发送请求?

[英]How to send request, by using RESTFul web services?

I have sucessfully received value from http://rest-service.guides.spring.io/greeting by using RESTFul and json web services. 我已经通过使用RESTFul和json网络服务从http://rest-service.guides.spring.io/greeting成功地获得了价值。 But unable to send my own text box value in request to my own server running apache on another machine. 但是无法将请求中的文本框值发送到在另一台计算机上运行apache的服务器。

my working code -: 我的工作代码-

- (IBAction)fetchGreeting;
{
    NSURL *url = [NSURL URLWithString:@"http://rest-service.guides.spring.io/greeting"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response,
                                               NSData *data, NSError *connectionError)
     {
         if (data.length > 0 && connectionError == nil)
         {
             NSDictionary *greeting = [NSJSONSerialization JSONObjectWithData:data
                                                                      options:0
                                                                        error:NULL];
             self.greetingId.text = [[greeting objectForKey:@"id"] stringValue];
             self.greetingContent.text = [greeting objectForKey:@"content"];
         }
     }];
}

But it stop working when i change NSURL *url = [NSURL URLWithString:@" http://rest-service.guides.spring.io/greeting "]; 但是当我更改NSURL * url = [NSURL URLWithString:@“ http://rest-service.guides.spring.io/greeting ”]时,它将停止工作; value to my own server address, and also unable to wrap my own text box value in request. 值到我自己的服务器地址,也无法在请求中包装我自己的文本框值。

We usually add our textfield data into the request like this. 我们通常将这样的文本字段数据添加到请求中。

NSString *url =[NSString stringWithFormat:@" http://rest-service.guides.spring.io/greeting/%@ ",textFied.text]; NSString * url = [NSString stringWithFormat:@“ http://rest-service.guides.spring.io/greeting/%@”,textFied.text ];

Can you show how your URL look like? 您可以显示网址的样子吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium WebDriver在UI下测试RESTful Web服务 - How to test RESTful web services under UI using selenium webdriver 如何使用RESTlet在RESTful Web服务中强制执行“会话”? - How to enforce 'sessions' in RESTful web services using RESTlet? 如何使用Jersey在RestFul Web服务中添加阵列名称 - How to add array name in RestFul web services using Jersey 如何使用Spring RestTemplate调用HTTPS restful Web服务 - How to call HTTPS restful web services using Spring RestTemplate 使用Jersey REStful Web服务返回响应? - Returning response using Jersey REStful web services? 使用Jackson异常构建RESTFul Web服务 - Building RESTFul Web Services using Jackson Exception 使用 jackson REST web 服务(RESTful Z38008DD81C2F4D7985ECF6839D47D60BC4555EE00C3FZ web 服务(RESTful Z38008DD81C2F4D7985ECF)@EV0ZCE8 - Request not processing using jackson REST web services (RESTful Spring Controllers) @PathVariable 如何将嵌套的JSON输入发送到Restful Web服务(使用Java)? - How to send nested JSON input to Restful web service (using Java)? 如何使用Web Service Restful以JSON格式将图像发送到MySQL - How send image to mysql using web service restful in format json 如何将DTO传递到Restful Web服务 - How to Pass the DTO to the Restful web services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM