Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom header in HttpRequest get #132

Closed
frazzaglia opened this issue Mar 13, 2017 · 4 comments
Closed

Custom header in HttpRequest get #132

frazzaglia opened this issue Mar 13, 2017 · 4 comments

Comments

@frazzaglia
Copy link

Hi all,

I don't be able to add a custom headers to HttpRequest.
I tried with:

HttpRequest.get(url).basic(username,password);
req.header("myCustomHeader", "true");
...

but no custom header is added to http request.
How can I solve it? What's the problem?
Thanks.

@rferreira
Copy link

As described in the documentation, you need to set the headers while creating the HttpRequest:

String contentType = HttpRequest.get("http://google.com")
                                .accept("application/json") //Sets request header
                                .contentType(); //Gets response header

afterwards is too late.

@frazzaglia
Copy link
Author

frazzaglia commented Mar 13, 2017

@rferreira Thanks for the reply.
I have another little problem, with:

HttpRequest req = HttpRequest.get(url).basic(user.getUsername(), user.getPassword()).header("myCustomHeader", "true");

it doesn't work, but with:

HttpRequest req = HttpRequest.get(url).header("Authorization", "Basic dasadjosjdajsodiajiosd").header("myCustomHeader", "true");

it works fine.
Why?
Thanks a lot.

@rferreira
Copy link

Not work how? What error are you seeing?

@frazzaglia
Copy link
Author

I'm sorry, it was my mistake.
Your solution works fine.
Thanks a lot.

I'm going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants