Post 使用 Jersey 的数据
Post Data using Jersey
我正在尝试向第三个 paty 发出等同于以下内容的请求:
curl -G -X GET -u {API KEY}:X https://some.com/api/head/remotelogin.json -d 'id=1234&msg=hello'
第三方也使用id
来验证请求。
下面是我写的界面:
public interface ThirdParty Client {
@POST
@Path("api/head/remotelogin.json")
@Produces(MediaType.APPLICATION_JSON)
@Consumer(MediaType.APPLICATION_FORM_URLENCODED)
Response authenticate(@HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader, String payload)
}
我不确定如何构建负载,我是否正确使用 @Consumer(MediaType.APPLICATION_FORM_URLENCODED)
?
我正在 Java 中执行我的 post 请求,比如
final Response response = ThirdPartyClient.authenticate(base64encoded("{API KEY}:X"), "id=1234&msg=hello");
我得到 200
,但是 id
是错误的。
我刚接触 Jersey,整个下午都在阅读文档并进行尝试。
睡了一觉后,答案是……
@GET
@Path("api/head/remotelogin.json")
@Produces(MediaType.APPLICATION_JSON)
Response authenticate(@HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader, @QueryParam("id") String id, @QueryParam("msg") String msg);
final Response response = ThirdPartyClient.authenticate("Basic " + base64encoded("{API KEY}:X"), "1234", "hello");
这里"Basic "
是必不可少的
我正在尝试向第三个 paty 发出等同于以下内容的请求:
curl -G -X GET -u {API KEY}:X https://some.com/api/head/remotelogin.json -d 'id=1234&msg=hello'
第三方也使用id
来验证请求。
下面是我写的界面:
public interface ThirdParty Client {
@POST
@Path("api/head/remotelogin.json")
@Produces(MediaType.APPLICATION_JSON)
@Consumer(MediaType.APPLICATION_FORM_URLENCODED)
Response authenticate(@HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader, String payload)
}
我不确定如何构建负载,我是否正确使用 @Consumer(MediaType.APPLICATION_FORM_URLENCODED)
?
我正在 Java 中执行我的 post 请求,比如
final Response response = ThirdPartyClient.authenticate(base64encoded("{API KEY}:X"), "id=1234&msg=hello");
我得到 200
,但是 id
是错误的。
我刚接触 Jersey,整个下午都在阅读文档并进行尝试。
睡了一觉后,答案是……
@GET
@Path("api/head/remotelogin.json")
@Produces(MediaType.APPLICATION_JSON)
Response authenticate(@HeaderParam(HttpHeaders.AUTHORIZATION) String authHeader, @QueryParam("id") String id, @QueryParam("msg") String msg);
final Response response = ThirdPartyClient.authenticate("Basic " + base64encoded("{API KEY}:X"), "1234", "hello");
这里"Basic "
是必不可少的