简体   繁体   English

RESTful服务-GET和POST请求不起作用

[英]RESTful Services - GET and POST requests not working

I am using an example given in RESTful Java client with Jersey client to practice GET and POST requests. 我正在使用RESTful Java客户端和Jersey客户端中给出的示例来练习GET和POST请求。 I downloaded the code and tried running on Eclipse Neon. 我下载了代码并尝试在Eclipse Neon上运行。 I used Tomcat v8.0. 我使用了Tomcat v8.0。 But it's not giving the intended output as explained in that demo. 但这并未提供该演示中所说明的预期输出。 The 'GET' request is giving response in JSON format but there is no line as "Output from server...". “ GET”请求以JSON格式给出响应,但是没有一行作为“来自服务器的输出...”。 Am I missing a point here? 我在这里遗漏了一点吗? And when I try 'POST' request, its showing an error HTTP Status 405 - Method Not Allowed. 当我尝试“ POST”请求时,它显示错误HTTP状态405-不允许使用方法。 Screenshot is below. 屏幕截图如下。

在此处输入图片说明

Could anyone help me understand where I am going wrong in this? 谁能帮助我了解我在这方面出了什么问题?

Thanks in advance! 提前致谢!

It would appear that URL only supports GET. URL似乎仅支持GET。

Try: 尝试:

curl -XPOST http://localhost:8080/RESTfulExample/rest/json/metallica/post

It would appear the GET version of that is (which you can user in your browser): 它将显示为的GET版本(您可以在浏览器中使用该版本):

curl -XGET http://localhost:8080/RESTfulExample/rest/json/metallica/get
  1. With the HTTP GET request, you are getting what you want. 通过HTTP GET请求,您将获得所需的内容。 The tutorial means that the line after "Output from Server .... " is what the server sends. 本教程意味着“服务器输出....” 之后的行是服务器发送的内容。

  2. With the HTTP POST request, you should post something using an interface (eg Postman extension of Chrome browser, curl command line client etc.). 使用HTTP POST请求,您应该使用界面发布内容(例如Chrome浏览器的Postman扩展名,curl命令行客户端等)。 Merely connecting to the POST URL in the browser is not going to actually post anything to the server. 仅在浏览器中连接到POST URL并不会实际将任何内容发布到服务器。 Please see Wikipedia on HTTP GET and HTTP POST request. 有关HTTP GET和HTTP POST请求,请参阅Wikipedia。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM