[英]How to send a POST requests with a JSON that contains a map using postman?
我正在尝试使用邮递员在 POST 请求中发送包含地图的 JSON。 我已经尝试了很多组合,不幸的是都无济于事。
我将 Content-Type 设置为 application/json。 我见过这个问题: 在邮递员邮寄请求中发送地图,但那里提供的建议没有帮助。
这是我到目前为止尝试过的: Key 是payload
,然后 Value 是:
以下是一些应该处理此问题的 Java 类:
@RequestMapping(method = RequestMethod.POST, value = "/send/singleUserReq")
@ResponseBody
public String sendNotificationToSingleUser(@RequestBody SingleUserRequest singleUserRequest) {
//...
}
public abstract class Request {
private String deviceType;
private Map<String, String> payload;
private String appId;
}
public class SingleUserRequest extends Request {
private String deviceId;
}
编辑:
当我向邮递员发送以下请求时:
http://localhost:8080/api/send/singleUserReq?deviceType=ios&payload={"message": "message1", "country":"germany"}&appId=appName1&deviceId=12345
我在 java 端收到此错误: Invalid character found in the request target [/api/send/singleUserReq?deviceType=ios&payload={%22message%22:%20%22message1%22,%20%22country%22:%22germany%22}&appId=appName1&deviceId=12345]. The valid characters are defined in RFC 7230 and RFC 3986
Invalid character found in the request target [/api/send/singleUserReq?deviceType=ios&payload={%22message%22:%20%22message1%22,%20%22country%22:%22germany%22}&appId=appName1&deviceId=12345]. The valid characters are defined in RFC 7230 and RFC 3986
看起来您没有在请求中发送正确的 JSON。 根据您的其余端点,JSON 应为SingleUserRequest
类型。
{
"deviceId" : "<your-device-id>",
"deviceType" : "<your-device-type>",
"payload" : {"message": "message1", "country":"germany"},
"appId" : "<your-app-id>"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.