0

I'm using library okHttpClient for form-based authentication(Content-type: application/x-www-form-urlencoded), j_security_check. when I login in application I'm getting the Set-Cookie value jsessionId in network response header. however, when the same I'm testing with postman then Set-Cookie is missing in response headers.

Also, the Cookie jsessionId is coming in Cookie tab with postman, but missing in Headers tab. please refer to screenshot attached. I'm not sure if there is any way to read the value of jsession directly from cookie tab.

Any suggestions or help would be really helpful! Thank you.

I am expecting the key(Set-Cookie) and value(jsessionId) in Headers tab.enter image description here

below is the code that am trying.

OkHttpClient client = new OkHttpClient.Builder().build();
MediaType media = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(media, "j_username=NEWRETAILUSER&j_password=Welcome@1");
Request request = new Request.Builder().url("http://10.2.2.239:4423/digx/cz/v1/security?locale=en")
.addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Accept", "*/*").addHeader("Accept-Encoding", "gzip,deflate").addHeader("Accept-Language", "en-US,en;q=0.9").addHeader("Connection", "keep-alive").addHeader("Content-Length", "47").addHeader("Content-type", "application/x-www-form-urlencoded").addHeader("Host", "10.2.2.239:4423").addHeader("Origin", "http://10.2.2.239:4423").addHeader("Referer", "http://10.2.2.239:4423/index.html?module=login").addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36").method("POST", body).build();    

Response response = client.newCall(request).execute();
System.out.println(response.headers());
System.out.println(response.code());

0 Answers0