python requests 怎么访问 java springboot 带 @requesbody 参数的接口

java 接口如下

    @RequestMapping("/batchAdd")
    public void add(@RequestBody Params params) {
        xxxx

    }
package com.lty.dispatch.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lty.dispatch.entity.Plan;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class Params {

    String cityCode;
    String lineId;
    Integer direction;
    List list;
    String targetDate;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    Date start;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    Date end;

}

python 访问这个接口怎么访问呢?

注意两点:

1.设置Content-Type: application/json  。

2.参数用json转化一下

data = {"cityCode": "130400", "lineId": "711", "direction": 0,
        "list": [{'startTime': "2020-06-25 09:05:00",'driver_name':'甲'}],
        "start": "2020-06-25 08:00:00", "end": "2020-06-25 11:00:00",
        "targetDate": "2020-06-25"}
re = requests.post("http://localhost:8087/manual/batchAdd", json.dumps(data),
                   headers={"Content-Type": "application/json"})

print(re.text)

 

你可能感兴趣的:(python requests 怎么访问 java springboot 带 @requesbody 参数的接口)