Java 重启:无法确定如何序列化内容类型application/x-www-form-urlencoded。如何使用键/值结构创建请求?

Java 重启:无法确定如何序列化内容类型application/x-www-form-urlencoded。如何使用键/值结构创建请求?,java,rest-assured,rest-assured-jsonpath,Java,Rest Assured,Rest Assured Jsonpath,我有以下邮递员收藏: { “信息”:{ “_postman_id”:“b172f7d9-xxxxxxx”, “名称”:“保护”, “架构”:https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, “项目”:[ { “名称”:“仅保护示例IP”, “请求”:{ “方法”:“发布”, “标题”:[ { “键”:“内容类型”, “值”:“application/x-www-form-urlencoded” } ]

我有以下
邮递员
收藏:

{
“信息”:{
“_postman_id”:“b172f7d9-xxxxxxx”,
“名称”:“保护”,
“架构”:https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
“项目”:[
{
“名称”:“仅保护示例IP”,
“请求”:{
“方法”:“发布”,
“标题”:[
{
“键”:“内容类型”,
“值”:“application/x-www-form-urlencoded”
}
],
“正文”:{
“模式”:“urlencoded”,
“URL编码”:[
{
“密钥”:“ApiKey”,
“值”:“62fdc812-be58-xxxxx”,
“类型”:“文本”
},
{
“密钥”:“TagId”,
“值”:“1111”,
“类型”:“文本”
},
{
“密钥”:“客户端”,
“值”:“200.55.111.111”,
“类型”:“文本”
},
{
“键”:“请求URL”,
“值”:http://awesomeSite.com",
“类型”:“文本”
},
{
“键”:“资源类型”,
“值”:“文本/html”,
“类型”:“文本”
},
{
“键”:“方法”,
“值”:“获取”,
“类型”:“文本”
},
{
“密钥”:“主机”,
“价值”:“awesomeSite.com”,
“类型”:“文本”
},
{
“密钥”:“用户代理”,
“值”:“Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/87.0.4280.88 Safari/537.36”,
“类型”:“文本”
},
{
“密钥”:“接受”,
“值”:“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed exchange;v=b3;q=0.9”,
“类型”:“文本”
},
{
“键”:“接受语言”,
“值”:“en-IL,en-US;q=0.9,en;q=0.8,my;q=0.7”,
“类型”:“文本”
},
{
“密钥”:“接受编码”,
“值”:“gzip,deflate,br”,
“类型”:“文本”
},
{
“钥匙”:“头颅”,
“值”:“主机、用户代理、接受、接受语言、接受编码、Cookie”,
“类型”:“文本”
}
]
},
“url”:{
“原始”:https://other.awesome.com/test-api",
“协议”:“https”,
“主持人”:[
“其他”,
“太棒了”,
“com”
],
“路径”:[
“测试api”
]
}
},
“答复”:[]
},
//.........
我需要使用
rest assured
framework创建相同的请求

我尝试创建一个带有键/值的贴图,并将其放到主体中:

Map key=newhashmap(){{
卖出(“ApiKey”、“62fdc812-be58-xxxxxx”);
put(“TagId”,“1111”);
//...
}};
RestAssured.given()
.contentType(“application/x-www-form-urlencoded”)
.车身(钥匙)
.when().post(“https://other.awesome.com/test-api")
.然后()
.状态代码(200);
但我得到了一个错误:

java.lang.IllegalArgumentException:无法序列化,因为无法确定如何序列化内容类型application/x-www-form-urlencoded

如果我使用
formParams
而不是
body

restassed.given()
.log().all()
.formParams(键)
.when().post(“https://other.awesome.com/test-api")
.然后()
.状态代码(200);
我得到以下错误:

预期状态代码与实际状态代码不匹配
HTTP/1.1 415不支持的媒体类型
内容长度:149
内容安全策略:默认src“无”
内容类型:text/html;字符集=utf-8
日期:2021年1月5日星期二09:50:12 GMT
X-Content-Type-Options:nosniff
错误
不支持的媒体类型
如何正确构建此模式的放心请求?


  • 其他信息:
PostMan
中,请求包含
正文
中的
键/值
映射。选项卡
参数
为空。但在代码中,在第二种情况下,
正文
部分中没有任何数据:

  • 邮递员:

  • 代码日志:
你就快到了

地图:

RestAssured.given().formParams(keys).when().post("https://other.awesome.com/test-api").then()
                .statusCode(200);
RestAssured.given().log().all()
                .config(RestAssured.config()
                        .encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
                .formParams(keys).when().post("https://other.awesome.com/test-api").then().statusCode(200);
请放心,将
内容类型设置为
应用程序/x-www-form-urlenco
RestAssured.given().formParams(keys).when().post("https://other.awesome.com/test-api").then()
                .statusCode(200);
RestAssured.given().log().all()
                .config(RestAssured.config()
                        .encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
                .formParams(keys).when().post("https://other.awesome.com/test-api").then().statusCode(200);
import static io.restassured.config.EncoderConfig.encoderConfig;