我有一个 Python 脚本,它将数据发布到服务器 url,如下所示。我想使用 unirest for Java 来实现这一点。如何在 Java 中为 unirest post 请求添加参数/标头值
Python脚本:
url = 'http://??????????????????/SaveTimeSeriesData'
params = {'clientId': 'admin', 'tenantId': '075841cb-d7fa-4890-84ea-fdd7d7c65b65', 'destinationId': 'TimeSeries','content-type': 'application/json','content':json.dumps(HTLT_DATA.__dict__)}
try:
response= requests.post(url, params=params, proxies=proxies)
print response
except Exception as x:
print x
服务器端点代码是:
@RequestMapping(value = "/SaveTimeSeriesData", method = RequestMethod.POST)
public @ResponseBody String saveMachineData(
@RequestHeader(value = "authorization", required = false) String authorization,
@RequestParam("clientId") String clientId, @RequestParam("tenantId") String tenantId,
@RequestParam("content") String content)
{
java中最统一的代码是什么?下面的代码是否会达到与 python 脚本相同的结果
Unirest.post("http://???????????????/SaveTimeSeriesData")
.field("content", mo)
.field("tenantId", "075841cb-d7fa-4890-84ea-fdd7d7c65b65")
.field("clientID","admin")
.field("content-type","application/json")
.asJson();