You need to sign in to do that
Don't have an account?
kodeX
Adding comments needs HttpEntityBody
Rest format for commenting is-
../chatter/feed-items/0D590000006SY64CAG/comments?text=my comment added successfully!
Above, Underlined portion is feeditemid, bold text is my comment.
But when i execute,
It gives error as -
[{"message":"The HTTP entity body is required, but this request has no entity bo
dy.","errorCode":"JSON_PARSER_ERROR"}]
There are methods-> setRequestHeader, setParams in HttpMethod interface,
but there is no method like "setEntityBody".
How to set the entity body in HttpMethod?
Every HTTP client library should let you set the body. You might find it helpful to read some tutorials on how HTTP requests are structured.
I believe in Java the method is PostMethod.SetRequestEntity(): http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/EntityEnclosingMethod.html#setRequestEntity(org.apache.commons.httpclient.methods.RequestEntity)
All Answers
What "content-type" header value are you providing? If you are specifying "application/json" then you can't use query parameters like "text".
If you are using a content-type of "application/json" then "HTTP Entity Body" refers to the JSON that is expected to be found in the request body.
Remember:
"content-type" indicates the type of input you are providing
"accept-type" indicates the type of output you are expecting back
Hey Chris,
Same question- How to specify json/xml Http entity body in java?
Suppose for new comment entity body is-
How do i actually put the above body in HttpMethod java code?
Considering, messageSegments array of <key,value> pairs, Could you provide the code snippet?
I tried doing the following with xml body-
Still it is returning the same entity body error!
How to put entity body in code?
Don't call "setRequestHeader" to set the body. What you are doing here is creating an HTTP header value called "<Body>". This won't work.
The "header" and the "request body" are 2 completely separate parts of your HTTP request. Your programming language should give you a method to let you either explicitly set the request body or to write it in with a stream.
Hey Chris,
I did not find any java method to set request body in HttpMethod.
Is there any other workaround?
Every HTTP client library should let you set the body. You might find it helpful to read some tutorials on how HTTP requests are structured.
I believe in Java the method is PostMethod.SetRequestEntity(): http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/EntityEnclosingMethod.html#setRequestEntity(org.apache.commons.httpclient.methods.RequestEntity)
Thanks CHRIS!!
It WORKED!!
import org.apache.commons.httpclient.methods.StringRequestEntity;
Here is the code-
Import StringRequestEntity