2

I hava a django rest framework web service that works fine with httpie and firefox: when I request with httpie I have a json formatted answer and when I request with firefox an html formatted one (httpie is a http client). Now I'm building java API to communicate with services. I'm using URL class to perform requests. I can receive html-formatted answers from the server if I don't override the content-type property. So I looked how httpie overrides this property and did the same:

connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
connection.setRequestProperty("Accept", "*\\*");

Now the communication end with Http 406 error, which means that client can't accept the answer.

If I use only the content-type property I have no error but still the html-formatted answer

Does anyone know how to solve it?

EDIT (adding requests' header):

httpie: GET /match/39.3280114/16.241917599999965/0/5/ HTTP/1.1 Host: 127.0.0.1:8001 Connection: keep-alive Accept-Encoding: gzip, deflate Accept: / User-Agent: HTTPie/0.9.3

java-API GET /match/39.3280114/16.241917599999965/0/5/ HTTP/1.1 Host: 127.0.0.1:8001 Accept-Encoding: gzip, deflate Accept: ** User-Agent: Java-API

Solved: I was using the wrong slash for Accept property

1
  • Can you show the full headers of the request? Commented May 10, 2016 at 15:14

1 Answer 1

1

Your Accept header is malformed. It should be:

Accept: */*

See RFC 7231 § 5.3.2.

However, */* means “any media type.” If you actually want a specific media type (JSON), you should request it:

Accept: application/json
Sign up to request clarification or add additional context in comments.

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.