# Okta Java SDK - Set Request header/Retrieve Response header

**URL:** <https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668>\
**Category:** Questions\
**Created:** [October 20, 2021, 7:05pm UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668 "2021-10-20T19:05:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abta](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@abta](https://devforum.okta.com/u/abta)\
**Post date:** [October 20, 2021, 7:05pm UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668/1 "2021-10-20T19:05:09Z")

</div>

We are using Okta Java SDK, and we have a requirement to set the client ip address (x-forwarded-for) and to log the response header (x-forwarded-for) return by Okta.

But I don’t see any option to either set the header or retrieve the response header using SDK. How can I implement this or is there any way to customize the okta Client to achieve this ?

Update:  
For setting the header, there is an option as below, but that would mean not using the API objects (User, Factor, Group etc)

```auto
oktaClient.http().addHeaderParameter("x-forwarded-for", "ip-address");

```

---

<div class="post-metadata">

**Author:** ![PatrickM](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@PatrickM](https://devforum.okta.com/u/PatrickM)\
**Post date:** [June 16, 2022, 4:56pm UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668/2 "2022-06-16T16:56:48Z")

</div>

I am also interested in setting the “x-forwarded-for” header for API requests through the Java API. Abta, did you find anything on this topic?

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [June 17, 2022, 2:55am UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668/3 "2022-06-17T02:55:05Z")

</div>

Hello!

If you are using Okta’s Java Auth SDK, it has built in support: [GitHub - okta/okta-auth-java: okta-auth-java](https://github.com/okta/okta-auth-java#setting-request-headers-parameters-and-device-fingerprinting)

If you are using the Management SDK (okta-sdk-java), you would need to use the “call other endpoints” technique: [GitHub - okta/okta-sdk-java](https://github.com/okta/okta-sdk-java#call-other-api-endpoints)

You can still use the API objects, but you will need to set in the URLs, for example, something like:

```java
User user = client.http()
    .setBody(yourUserObject)
    .addHeaderParameter("x-forwarded-for", "ip-address")
    .post("/api/v1/users/<user-id>", User.class);

```

(this is a combination of cut/paste and memory, so it might need to be tweaked a little)

If you would like to see built in support for this please open a feature request on the GitHub repo: [Issues · okta/okta-sdk-java · GitHub](https://github.com/okta/okta-sdk-java/issues)

---

<div class="post-metadata">

**Author:** ![PatrickM](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@PatrickM](https://devforum.okta.com/u/PatrickM)\
**Post date:** [June 17, 2022, 8:03am UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668/4 "2022-06-17T08:03:03Z")

</div>

Thanks very much for that code sample. I think I will request it as a feature in the Okta SDK project.

Edit: I have opened issue [Add ability to set x-forwarded-for header without using .http() "other requests" method · Issue #739 · okta/okta-sdk-java · GitHub](https://github.com/okta/okta-sdk-java/issues/739). Thanks again for your help and guidance, bdemers.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 12, 2024, 9:13pm UTC](https://devforum.okta.com/t/okta-java-sdk-set-request-header-retrieve-response-header/16668/5 "2024-02-12T21:13:22Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
