简体   繁体   English

我应该如何在http post请求(spring boot)的请求负载中传递json数据

[英]How should I pass json data in the request payload of http post request (spring boot)

I have got a Json data , which I need to pass into POST request using httpActionBuilder.client(httpClient).post("/API").payload(jsonPayloadHere);我有一个Json 数据,我需要使用httpActionBuilder.client(httpClient).post("/API").payload(jsonPayloadHere);将其传递到POST 请求中httpActionBuilder.client(httpClient).post("/API").payload(jsonPayloadHere);

Is there any way I can pass Json data as a argument in the payload() method above.有什么方法可以将 Json 数据作为参数传递到上面的 payload() 方法中。 One way of doing it is passing it as string, which is prone to errors easily(I just don't want to pass it as String, not effective).一种方法是将它作为字符串传递,这很容易出错(我只是不想将它作为字符串传递,无效)。

My JSON looks like:我的 JSON 看起来像:

{
    "Date": "2020-02-25",
    "Id": 1,
    "Names": [
        {
            "firstName": "AB",
            "Cd": 1,
            "surname": "CD"
        }
    ],
    "dateOfBirth": {
        "countryId": 1,
        "DateCD": 1,
        "dateOfBirth": "2010-01-02"
    }
}

Thanks in advance:)提前致谢:)

You can store your request body in eg.您可以将请求正文存储在例如。 payload.json file and load it with ClassPathResource like this: payload.json文件并使用ClassPathResource加载它,如下所示:

httpActionBuilder .client(httpClient) .post("/API") .payload(new ClassPathResource("template/payload.json"));

Files payload.json must be stored in resources directory.文件payload.json必须存储在资源目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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