簡體   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