可以在 HttpHeader 中设置“application/x-www-form-urlencoded”,但是我想为 requestbody 设置,请您指导我吗?
示例 json:
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "Tohid",
"type": "text"
},
{
"key": "password",
"value": "*makari",
"type": "text"
},
{
"key": "grant_type",
"value": "password",
"type": "text"
}
]
},
代码 :
HttpHeaders headers = new HttpHeaders();
headers.add(PostEnum.CONTENT_TYPE.getValue(), PostEnum.APPLICATION_URLENCODED.getValue());
HttpEntity<?> requestEntity = new HttpEntity<>(gson.toJson(requestBody), headers);