1

How to send the Http Content-Length header in Apache JMeterHttp Request?

I'm using Apache JMeter to send a get request to a configured endpoint, as shown in the following diagram.

enter image description here

There, I'm using the parameters tab to set the request parameters, However, JMeter doesn't send the content-length header to the server.

I checked this by printing the request in the server. Following is the server received request.

GET /io?Message=Nelika HTTP/1.1
Connection: close
Host: localhost:4333
User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_212)

How can I configure JMeter to send the content-length?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Pasindu Tennage
  • 1,480
  • 3
  • 14
  • 31

1 Answers1

1

JMeter doesn't send Content-Length on GET Request because it may be not expected:

Some servers fail if Content-Length is equal to 0

For other methods, add HTTP Header Manager as a child of your HTTP Request

Add row with name: Content-Type and value as: application/x-www-form-urlencoded

Notice that you aren't sending any entity body in your GET request, thus it'll send 0 value

EDIT

A work around is to add to HTTP Header Manager row with Content-Length value (it'll be overridden)

Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I added the Content_Type in Http Header Manager. Then the server receives the content type as follows. GET /io?Message=Nelika HTTP/1.1 Connection: close Content-Type: application/x-www-form-urlencoded Host: localhost:4333 User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_212 But what I want is to get the content length (the length of the get parameters) – Pasindu Tennage May 20 '19 at 11:45
  • 1
    @PasinduTennage try to send POST request with request body which will be more relevant to sending `Content-Length` – Ori Marko May 20 '19 at 11:47
  • With post requests (even without request body), I get the content-length. Seems like JMeter does not send the Content-Length for GET Requests. – Pasindu Tennage May 20 '19 at 11:52
  • 1
    @PasinduTennage yes, you are right, this is because in GET request (quoted) *Some servers fail if Content-Length is equal to 0* https://github.com/apache/jmeter/blob/c7b9bb935e5e4e01cbc89b4fba6cd4db78d51f1d/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java – Ori Marko May 20 '19 at 11:59