ADD EMPTY HEADER IN JMETER SAMPLE REQUEST

ADD EMPTY HEADER IN J-METER SAMPLE REQUEST

          In Jmeter Test Plan if you have multiple Request Sampler with globally defined HTTP Request Header and in one Request Tester does not want to use globally defined HTTP Request Header and want to edit/delete the Header with new header value.

     Solution : - Add Bean Shell Preprocessor to that request and write the following code .

import org.apache.jmeter.protocol.http.control.Header;
sampler.getHeaderManager().remove(1);

In Below Test Plan HTTP Request Header cointains 2 headers values ->
Content-Type – Application/json
Authorization – ${access_token}




In Request OauthToken1,  I want to use header value as
Content-type – text/xml and want to remove Authorization value .
Add Bean shell preprocessor to OauthToken 1 . with above-defined code .


Result :- In OauthToken1 Request , header values is passed as Content-type – text/xml with no authorization .










Comments

  1. Hi, I'm trying to change the header parameters(Content-Type: text/plain; charset=US-ASCII to Content-Type: application/json ) of POST Request in JMeter - sending JSON Text as mutlipart/form-data parameter with content application/json.

    From your code snippet - sampler.getHeaderManager().remove(1)- its not helping to remove these sampler headers.

    --v_23LkJlLQpYLpcElRptQYb74v7-UeP
    Content-Disposition: form-data; name="definition"
    Content-Type: text/plain; charset=US-ASCII
    Content-Transfer-Encoding: 8bit

    {"name":"TestDefinition","Id":"7d12d44c2"}
    --v_23LkJlLQpYLpcElRptQYb74v7-UeP--

    Can you Please leave me suggestions to get through

    ReplyDelete

Post a Comment

Popular posts from this blog

How To Automate Rest API in Postman

Constructing Curl from Python , HTTP , PHP , Java Request