final ClientRequest request = new ClientRequest();
request.setMethod(new HttpString(requestMethod));
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, new ClientCallback<ClientExchange>() {
@Override
public void completed(ClientExchange clientExchange){}
@Override
public void failed(IOException e){}
}
I am following the example for the Undertow Client API. How do I add cookies to the request?
Note if propagation of the request cookies is not what you need (sorry Op) you can set your own cookies when configuring the client factory. Inject the IHttpClientFactory into your controller or middleware.
Undertow is a lightweight open-source Java web server, and the default web server in WildFly. It comes with several handlers, one of which is RequestDumpingHandler for logging HTTP exchanges. # Script for activating request logging based on Undertow's RequestDumpingHandler on WildFly.
To open up Developer Tools in Chrome, you can hold down CTRL + Shift + I on your keyboard or you can manually navigate to it in the “More tools” menu: A screenshot showing the location of Developer Tools in Chrome. The location of the Application tab in Developer Tools. Select the Cookies menu.
Note, that despite cookies have a separate getCookies () method, they are just http headers in the end, so the getHeaders () method won't return your modified cookie list in the Cookie header. If you want getHeaders () to work, you have to override that method as well.
Cookies are stored in the request headers. Therefore you can do that:
final ClientRequest request = new ClientRequest();
request.setMethod(new HttpString(requestMethod));
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
request.getRequestHeaders().put(Headers.COOKIE, "name=value; name2=value2; name3=value3");
connection.sendRequest(request, new ClientCallback<ClientExchange>() {
@Override
public void completed(ClientExchange clientExchange){}
@Override
public void failed(IOException e){}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With