2

I need to make a POST call with a content-length equal to 0. So I tried setting the header to 0 when I make the call but in the web service that receives the call the content-length is much greater than 0.

Request

let url = '/blah/blah/'+ anUID +'/blah/' + anotherUID + '';
let headers = new Headers({'Content-Length': '0'});
let options = new RequestOptions({
  method: RequestMethod.Post,
  headers: headers,
});

return this.http.post(url, options)
  .map(this.extractData)
  .catch(this.handleError.bind(this));

The on in the receiving web service there is a check to make sure that the request's content length is 0.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("{anUID}/blah/{anotherUID}")
public Response myWebService(@PathParam("anUID") Integer anUID, @PathParam("anotherUID") Integer anotherUID,
        @Context ServletContext application, @Context HttpServletRequest request, @Context UriInfo info) {
    Response resp = Response.notModified().build();
    String method = request.getMethod();    // == "POST"
    int meh = request.getContentLength();   // = 172 NEEDS TO BE 0

    if (request.getContentLength() < 1) {
       ...
    }

    ...
}

What could I do differently to set the content-length equal to 0?

1
  • What is the purpose of making the content length as 0? Commented Mar 30, 2017 at 17:27

1 Answer 1

2

You don't need to set header. Just send empty body will do.

return this.http.post(url, '')
  .map(this.extractData)
  .catch(this.handleError.bind(this));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.