gpt4 book ai didi

java - 使用 postman 复制请求代码的 400 错误请求

转载 作者:行者123 更新时间:2023-12-01 16:42:33 24 4
gpt4 key购买 nike

我已从

获取请求代码
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
String json = String.format("{'sex': %s,'age': %d,'evidence': []}", gender, age);
RequestBody body = RequestBody.create(mediaType, json);
Request request = new Request.Builder()
.url("https://api.infermedica.com/covid19/diagnosis")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "*/*")
.addHeader("App-Id", "XXXXXX")
.addHeader("App-Key", "XXXXXXXXXXXXXXXXXXXXX")
.addHeader("User-Agent", "PostmanRuntime/7.19.0")
.addHeader("Accept", "*/*")
.addHeader("Cache-Control", "no-cache")
.addHeader("Postman-Token", "58fbac21-182b-41e0-bceb-0905d0605858,cd9580e6-f262-4440-ba33-b85877dd087c")
.addHeader("Host", "api.infermedica.com")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Content-Length", "56")
.addHeader("Connection", "keep-alive")
.addHeader("cache-control", "no-cache")
.build();

com.squareup.okhttp.Response response = client.newCall(request).execute();

我正在尝试发出发布请求。我已在 postman 中成功运行该请求。我已经从 postman 那里复制了代码。但是当我在 java 中运行请求时,我收到 400 Bad Request。我不知道为什么,因为所有标题和正文与 postman 中的完全相同。

最佳答案

您的输入中缺少性别引号

在此确认https://developer.infermedica.com/docs/covid-19

curl "https://api.infermedica.com/covid19/diagnosis" \
-X "POST" \
-H "App-Id: XXXXXXXX" -H "App-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" -d '{
"sex": "male",
"age": 30,
"evidence": []
}'

关于java - 使用 postman 复制请求代码的 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61835106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com