开发者

Length Required (411) - Length Required in a RESTlet client

Im new to REST and am developing a client to post data to a external hosted service. Im using org.reslet.resource.ClientResource to create a client

    Representation rep = new JsonRepresentation(json);
    rep.setMediaType(MediaType.APPLICATION_JSON);
    rep.setCharacterSet(CharacterSet.UTF_8);

    ClientResource clientResource = getClientResource();
    Representation reply = clientResource.post(rep);
    return readResponseStream(reply, clientResource);

however I get the following error

Exception in thread "main" Length Required (411) - Length Required
at org.restlet.resource.ClientResource.handle(ClientResource.java:858)
at org.restlet.resource.ClientResource.post(ClientResource.java:1197)
at org.mine.client.impl.RestClient.开发者_C百科post(RestClient.java:59)

The same code works for a get request

Representation reply = clientResource.get();

I'm using reslet api 2.0.8. This seems like the problem in post org.restlet: Posting JSON content against webservice returns HTTP error 411 (length required)

I have the following jars in the classpath

org.apache.commons.codec.jar org.apache.commons.logging.jar org.apache.httpclient.jar org.apache.httpcore.jar org.json.jar org.restlet.ext.json.jar org.restlet.jar

Any help would be greatly appreciated.


the problem is that GAE doesn't support HTTP chunked encoding, therefore serialized object can't be sent (via POST or PUT) to a GAE server. In Restlet Framework version 2.1 M4 we have a workaround available that buffers the HTTP entity to prevent chunk encoding. To use it, call the ClientResource#setRequestEntityBuffering(boolean) method with a "true" value. Note that this workaround isn't required for the GWT edition.

As you are using Restlet 2.0.8, I suggest you use the workaround published here : http://restlet.tigris.org/issues/show_bug.cgi?id=1219

Best regards, Thierry Boileau

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜