我需要使用Jersey客户端将大型JSON字符串从android发布到web服务。以下代码失败,HTTP状态505错误。看起来JSON字符串的长度导致了麻烦,因为当JSON字符串的长度不是太高时调用工作正常(我测试了200个字符长度)。我也怀疑这与android上的jersey库有关,因为在eclipse中运行的Jersey客户端可以正常使用相同的代码。在eclipse中,我甚至不必在请求中设置压缩头。有没有人知道我在这里缺少什么?
formData.add("payload",payload);
config = new DefaultClientConfig(); // SSL configuration
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
new HTTPSProperties(JerseyClientBKS.getHostnameVerifier(), JerseyClientBKS.getSSLContext(getApplicationContext())));
ServiceFinder.setIteratorProvider(new AndroidServiceIteratorProvider());
client = Client.create(config);
webResource = client.resource(getSeletctedAddress()+"/api/document/submitHybridJSON");
builder = webResource.queryParams(formData).getRequestBuilder();
for (NewCookie c : getCookies()) {
if (c.getValue().indexOf("_") != -1){
builder = builder.cookie(c);
}
}
builder = builder.header("Content-Encoding", "gzip");
builder = builder.header("Accept-Encoding", "gzip");
Log.d(TAG, "posting.... = ");
response =builder.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class);
Log.d(TAG,"response code "+response.getStatus());
Log.d(TAG,"valuesets "+response.getEntity(String.class));
答案 0 :(得分:0)
我通过发布一个InputStream而不是长JSON字符串解决了这个问题。