我正在使用Facebook Messenger应用程序(chatbot),我希望看到我收到的GET请求。我正在使用Spring Framework来启动http服务器和ngrok以使其在Facebook上可见。
Facebook向我发送webhooks并收到它们,但我不明白如何从此请求中提取数据。这是我在尝试 HttpRequest 接收GET请求时得到的结果。 ngrok screenshot(错误500)。
当我在没有HttpRequest
的情况下尝试时,我的响应为200(确定)。
我需要为 find 方法的参数添加什么来查看GET请求数据?
我的代码:
@RestController
public class botAnswer {
@RequestMapping(method= RequestMethod.GET)
public String find(HttpRequest request) {
System.out.println(request.getURI());
String aaa = "222";
return aaa;
}
}
答案 0 :(得分:0)
我猜HttpRequest
对你没有帮助。为简单起见,只需将HttpRequest
更改为HttpServletRequest
即可。您可以使用request.getParameter("...")
从中访问所有查询字符串参数。以下内容应该有效:
@RequestMapping(value = "/", method = RequestMethod.GET)
public String handleMyGetRequest(HttpServletRequest request) {
// Reading the value of one specific parameter ...
String value = request.getParameter("myParam");
// or all parameters
Map<String, String[]> params = request.getParameterMap();
...
}
This blog post显示如何使用@RequestParam
注释作为直接从HttpServletRequest
读取参数的替代方法。