繁体   English   中英

如何使用邮递员使用包含地图的 JSON 发送 POST 请求?

[英]How to send a POST requests with a JSON that contains a map using postman?

我正在尝试使用邮递员在 POST 请求中发送包含地图的 JSON。 我已经尝试了很多组合,不幸的是都无济于事。

我将 Content-Type 设置为 application/json。 我见过这个问题: 在邮递员邮寄请求中发送地图,但那里提供的建议没有帮助。

这是我到目前为止尝试过的: Key 是payload ,然后 Value 是:

  1. {消息:消息1,国家:德国},
  2. {“消息”:消息1,“国家”:德国},
  3. {"message": "message1", "country":"德国"},
  4. 其他一些具有多次转义尝试的选项 - 它们都不起作用。

以下是一些应该处理此问题的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM