我正在尝试从POSTMAN向Apache Tomcat服务器发布一些数据。我能够从服务器获取数据,但无法发布(端点不同)。
例如,当我从端点执行Get时:
http://coreapi.imagin8ors.org:8080/v1/child/140df552-eba9-42c3-8c9e-6d478637925f/learningpods_new/
但是当我尝试将一些数据发布到另一个端点:http://coreapi.imagin8ors.org:8080/v1/parent/
时,我得到405个响应代码(不允许该方法)。
HTML响应。
<!DOCTYPE html>
<html>
<head>
<title>Apache Tomcat/8.5.9 - Error report</title>
<style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style>
</head>
<body>
<h1>HTTP Status 405 - Method Not Allowed</h1>
<div class="line"></div>
<p>
<b>type</b> Status report
</p>
<p>
<b>message</b>
<u>Method Not Allowed</u>
</p>
<p>
<b>description</b>
<u>The specified HTTP method is not allowed for the requested resource.</u>
</p>
<hr class="line">
<h3>Apache Tomcat/8.5.9</h3>
</body>
我在做什么错了?我很困惑,因为GET操作给出了200状态代码,而POST提供了405。
这是一个授权问题,您必须提供一些用户名:密码来发布数据或一些ID足够吗?
什么是正确的方法?
感谢您的帮助。
答案 0 :(得分:1)
为了详细说明我的意见,一个特定的URL可能只有一个与之配合使用的HTTP动词。例如,获取网页时,URL可能为/index.html
。那是一个GET
请求,在这个例子中,一个POST
可能没有任何意义。
对于HTTP GET
动词,它表示服务器正在向客户端提供某些东西。 POST
有点复杂,但是通常它是客户端向服务器提供一些东西。
在Java代码中,我可能会有类似的内容:
@Path("/v1/hello")
@Produces({ MediaType.TEXT_PLAIN })
@GET
public Response getHello() {
return Response.ok("Hello!").build();
}
在此示例中,URL以/v1/hello
至GET
的简单字符串结尾。 POST
在这种情况下不起作用,因为尚未定义处理代码。这里的业务规则是,您只能从URL GET
进行任何操作,而不提供任何内容(即POST
或PUT
)。