I want to add header in my HTTPRequest
with variable but it will give error not taking it but when i pass direct string value in inverted commas it work well.
Hers is the code in 3rd header i am passing variable checksum
which contains String
value but it is not working and if i pass direct String
value it's work without problem.
HttpRequest request1 = (HttpRequest) HttpRequest.newBuilder()
.uri(URI.create("https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay"))
.header("accept", "application/json")
.header("Content-Type", "application/json")
.header("X-VERIFY",checksum)
.method("POST", HttpRequest.BodyPublishers.ofString("{\"request\":\"\"}"))
.build();
The most probable explanation is that you haven't overridden
toString()
method in the class of yourchecksum
. Try to override the method returningString
value of checksum:HttpRequestBuilder
converts an object passed intoheader()
method according to certain rules and for object of custom class it just callstoString()
method.