我有一个Python脚本,它将数据发布到服务器url,如下所示。我希望使用unirest for Java来实现这一点。如何为Java中的unirest请求添加参数/标头值
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();发布于 2016-01-16 02:11:54
没有任何更多的信息,我相信这是一个简单的错误与您的引号的位置。
.field("tenantId, "075841cb-d7fa-4890-84ea-fdd7d7c65b65")真的应该是
.field("tenantId", "075841cb-d7fa-4890-84ea-fdd7d7c65b65")请注意,租户Id没有引号。整行可能被视为字符串文本。如果这个修复了窃听器,请告诉我
https://stackoverflow.com/questions/34822690
复制相似问题