在 PostMan 上发送发帖请求
I have the following method I want to test using PostMan
public returnType name( String var1, String var2,String var3, String var4);
我尝试发送一个帖子请求来测试我发送了这样的一个,但它不起作用:
{
"var1": "GU4777",
"var2" : "HU 888",
"var3" : "NU 8890",
"var4" : "UJ 9909"
}
我收到此错误:< br> 我收到此错误: 10:11:16.588 [http-nio-8080-exec-3] WARN org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.InternalServerErrorException:HTTP 500 内部服务器错误 ;
Can you guys please tell me the exact syntax I can use?
提前谢谢您
I have the following method I want to test using PostMan
public returnType name( String var1, String var2,String var3, String var4);
I tried to send a post request to test I sent one like this but it does not work:
{
"var1": "GU4777",
"var2" : "HU 888",
"var3" : "NU 8890",
"var4" : "UJ 9909"
}
I get this error:
I get this error: 10:11:16.588 [http-nio-8080-exec-3] WARN org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
Can you guys please tell me the exact syntax I can use?
Thank you in advance;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rest API
为了完成您想做的事情,您首先需要一个 HTTP 服务器来侦听某个端点上的请求,我们将该端点称为
/test
。然后,服务器在收到请求时必须解析 JSON 请求正文,提取参数,然后可以使用这些参数调用方法
name()
。这里是一个使用 JavaScript 和 express.js 的服务器实现。对于这样的简单服务器,您不需要一个库(但为了简单起见,我在这里使用了一个库),并且您可以用几乎任何您喜欢的语言(例如 Java)来实现该服务器。
虽然另一种语言的语法会有所不同,但想法是相同的。
然后您需要启动您的服务器。在这种情况下,您可以通过执行
node server.js
来实现这一点,然后您可以使用 Postman 向服务器发送请求。首先,将 JSON 有效负载(= 问题中的 JSON)放入请求正文中,并使用
POST
请求点击localhost:3000/test
路由。然后,您应该会收到状态代码200
的响应。在服务器端你可以观察到这一点:
RPC/ gRPC
为了“直接”调用服务器上的函数,您可能需要查看RPC 或 gRPC 适合您的首选语言。
Rest API
In order to do what you want to do you first need a HTTP server that listens for requests on a certain endpoint let's call that endpoint
/test
.The server then must parse the JSON request body when it receives the request, extract the parameters and can then call the method
name()
using those parameters.Here an implementation of a server like this using JavaScript and express.js. You do not need a library for a simple server like that (but I have used one here by reason of simplicity) and you can implement the server in pretty much any language you like e.g. Java.
While the syntax will differ in another language the idea will be the same.
You then need to start your server. In this case you do that by executing
node server.js
and then you can send requests to the server using Postman.First, put your JSON payload (= the JSON from your question) into the request body and hit the
localhost:3000/test
route with aPOST
request. You should then receive a response with status code200
.On the server side you can observe this:
RPC/ gRPC
In order to "directly" invoke a function on a server you might wanna have a look at RPC or gRPC for your preferred language.
我决定使用请求路径希望解决这个问题。
I decided to use request path wish solved the issue.