我是Dropwizard / Jersey的初学者,所以请耐心等待。我正在从我的Dropwizard应用程序资源创建请求:
Client client = new JerseyClientBuilder(environment)
.using(new JerseyClientConfiguration())
.build("my-app-name");
String response = client
.target("https://api.parse.com/1/functions/myFunction")
.request(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.header("X-Parse-Client-Key", "mysecredclientcode")
.header("X-Parse-Session-Token", "mysecretsessiontoken")
.header("X-Parse-Application-Id", "mysecretapplicationid")
.post(Entity.text(
"{\"postId\":\"xP0Jc2lrqS\"}"
));
我想我尝试了所有可能的实体变体。*后面是MediaType。*没有运气。
这应该根据文档工作。我可以通过这种方式本地调用我的应用程序的其他端点,没有任何问题。但是对parse.com的请求返回以下实体:
{"code":107,"error":"invalid utf-8 string was provided"}
当我从bash卷曲时,我得到预期的回应。我觉得我尝试了一切,请你指点我正确的方向,我在这里做错了什么?
卷曲请求有效:
#!/usr/bin/env bash
curl -X POST \
-H "X-Parse-Application-Id: mysecretapplicationid" \
-H "X-Parse-Client-Key: mysecretclientkey" \
-H "X-Parse-Session-Token: mysecretsessiontoken" \
-d '{"postId":"xP0Jc2lrqS"}' \
https://api.parse.com/1/functions/myFunction
答案 0 :(得分:0)
即使您仍然遇到此问题,我也解决了在我的maven项目中添加以下属性的问题:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
此致