2

在与点火项目遇到相同问题后,我正在使用 loopj/android-async-http。

当我提交没有授权标头的 GET 时,一切正常:

AsyncHttpClient client = new AsyncHttpClient();
client.get(url, params, responseHandler);

我正在发送到 Jersey 服务器,并且日志过滤器显示了预期的数据:

INFO: 1 * Server in-bound request
1 > GET http://mydomain.com/myresource/
1 > host: mydomain.com
1 > accept-encoding: gzip
1 > user-agent: android-async-http/1.4.0 (http://loopj.com/android-async-http)
1 > connection: Keep-Alive

经过身份验证的 GET 也可以工作。

如果我对同一个 URL 的 POST 请求做同样的事情:

AsyncHttpClient client = new AsyncHttpClient();
String auth = user + ":" + pass;
client.addHeader("Authorization", "Basic " + Base64.encodeToString(auth.getBytes(), Base64.DEFAULT));
client.post(context, url, entity, "application/json", responseHandler);

服务器没有显示我希望看到的多个信息,我不明白为什么:

INFO: 2 * Server in-bound request
2 > POST http://mydomain.com/myresource/
2 > host: mydomain.com
2 > accept-encoding: gzip
2 > authorization: Basic GFzasomethingvalidhereXN0
2 > connection: Keep-Alive
  1. 为什么我看不到“Content-Type”标头?这是我遇到的主要问题,因为我的 Jersey 资源被注释为使用 application/json 数据

  2. 为什么我看不到“用户代理”标题?

我的泽西资源:

@Service
@Path("/myresource/")
public class MyResource {

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public MyDTO myEndPointMethod(MyDTO myDTO) {
   //something cool here
}
4

0 回答 0