[英]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.