0

I have the following cURL request:

curl -H "AuthToken: anything" http://localhost:9999/my_service/data?%24expand=total%2Callocated

I'd like to use Apache HttpClient to make this call in my application. My code is as follows:

HttpGet httpGet = new HttpGet(uri);
httpGet.setConfig(myConfig);
httpGet.addHeader("-H", "AuthToken: anything");
response = this.httpClient.execute(httpGet, httpClientContext);

However, this does not work - i get a response code 400.

What am i missing here? Any help would be greatly appreciated!

2 Answers 2

1

-H is an option for curl, not the actual HTTP header name your service is expecting.

I think you need to modify the header name here.

httpGet.addHeader("[Header name your service is expecting]", "AuthToken: anything");

And I guess it should look like this

httpGet.addHeader("AuthToken", "anything");
Sign up to request clarification or add additional context in comments.

Comments

1

Are you sure about -H parameter in

httpGet.addHeader("-H", "AuthToken: anything");

Looks like that -H is a just curl flag, so could you try just

httpGet.addHeader("AuthToken", "anything");

I don't know is this a root cause, but it looks like pretty strange.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.