【发布时间】:2021-04-22 23:31:32
【问题描述】:
一旦我在终端中点击 curl 代码,我就能够得到 200,所以我认为到目前为止我编写 testStytch 的方式还可以。但是一旦我尝试集成到一个 java 文件中,我就会得到一个错误的请求响应。我现在一点头绪都没有。 https://github.com/libetl/curl 这就是我所说的转换我的 curl 代码。
这是我得到的错误。 HttpResponseProxy{HTTP/1.1 400 错误请求 [日期:格林威治标准时间 2021 年 4 月 22 日星期四 23:21:42,内容类型:应用程序/json,内容长度:189,连接:保持活动,Traceparent:00-d3a39218eb8d091ffe3bf5cb474692ce-353a1a23da4e5dc4 -01] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 189,Chunked: false]}}
@RequestMapping(value = "/loginByStytch" , method = RequestMethod.POST)
public synchronized String loginByStytch(ModelMap model, HttpServletRequest
request) throws Exception {
mapper = new ObjectMapper();
String hashPassword;
UserInfoBean userInfoBean = mapper.readValue(request.getParameter("data"),
new TypeReference<UserInfoBean>() { });
String testStytch = "-k -X POST 'https://test.stytch.com/v1/magic_links/send_by_email' -u project-test-b3ca64c2-b0c8d73:secret-test-s5lO3O -H 'Content-Type: application/json' -d '{\"email\":\"yiikikkano@nllllc.com\",\"magic_link_url\":\"http://localhost:8080/ROOT/NC/authenticateByStytch\",\"expiration_minutes\":500}'";
HttpResponse response = curl(testStytch);
InputStream inputStream = response.getEntity().getContent();
String jsonContent = convert(inputStream, Charset.forName("UTF-8"));
request.getSession().setAttribute(Constant.SESSION_NAME, null);
return "redirect:/timeline";
}
【问题讨论】: