提问人:PatrickBateman 提问时间:11/8/2023 最后编辑:PatrickBateman 更新时间:11/9/2023 访问量:57
如何在java中发布请求以获取响应
How to post request in java to get the response
问:
我想以相同的格式发布请求。
POST /api/bla/bla/test/token HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic aaabbbCCCdddeeefffGGG
client_id=xxx&client_secret=yyy&grant_type=authorization_code
&code=3v6MJzt9vKtRkxpTFnkJG3IyspWC2k
&redirect_uri=xyz%2Ffolder
我已经实施了,但收到错误的请求(“错误:无法满足请求”)。 这就是我实现请求的方式
HttpRequest requestCrafted = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString("Vaffanculo"))
//.uri(URI.create(url))
.uri(URI.create("http://signin/v2/tokens?credential=passkey"))
.headers(listheaders.toArray(String[]::new))
.build();
尝试通过与站点交互并通过 Burpsuite 对其进行分析来手动执行发布请求,如果我修改发布请求,我会遇到相同的错误。
这工作正常
POST /api/bla/bla/test/token HTTP/2
Host: example.com
这将返回运行代码时发现的相同错误
POST http://example.com/api/bla/bla/test/token HTTP/2
Host: example.com
我尝试在创建 URI 时删除主机,只是传递它 /api/bla/bla/test/token,但它不起作用。我也在 URI.create 中使用了 http:/api/bla/bla/test/token 和 https:///api/bla/bla/test/token 但它不起作用。我该如何解决?(我必须使用HttpRequest)
答: 暂无答案
评论