简体   繁体   中英

posting large JSON string with Jersey client on android

I need to post large JSON string from android to a webservice using Jersey client. The below code fails with HTTP status 505 error. Looks like the length of the JSON string is causing the trouble because the call works fine when the length of JSON string is not too high(I tested with 200 characters lenght). I also suspect this has something to do with jersey library on android because the same exact code works fine from Jersey client running in eclipse. In eclipse I don't even have to set the compression header in the request. Does anybody have a clue what is that I'm missing here ?

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));

我通过发布InputStream而不是长JSON字符串解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM