4

My java snippet looks like:

...
String type = "text/plain;charset=UTF-8";
URL url = new URL("http://xxx/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoOutput(true);
conn.setRequestMethod("OPTIONS");
conn.setRequestProperty("Content-Type", type);
...

When I sniff what this sends it sends a

OPTIONS / HTTP/1.1

which appears to be the default.

However, I actually want to send

OPTIONS * HTTP/1.0

How would I do this?

2 Answers 2

3

You can't do that with "plain" java.net.URLConnection. Consider replacing by Apache Commons HttpClient which is less bloated and more configureable. You can force HTTP 1.0 mode by setting http.protocol.version to HttpVersion.HTTP_1_0 in HttpClient#getParams(). You can find an example in this document.

Sign up to request clarification or add additional context in comments.

5 Comments

OK - thanks - does the Apache client support the "*" parameter and how would I add it?
It's actually the request URI. I haven't used this particular method, so don't pinpoint me on it, but there's a OptionsMethod class taking an URI. You could pass * to it: hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/…
On HttpClient 4.0 there's no OptionsMethod, it's rather HttpOptions class (hc.apache.org/httpcomponents-client/httpclient/apidocs/org/…)
@The Elite Gentleman: That's another (newer) API :) Click at the link I provided in my comment. A good hint though, upgrading to HttpClient 4.0.
I know, on Apache sites, they've mentioned that we should rather use HttpClient 4.0 or higher since they've made it more flexible that it's previous releases. :-)
2

I agree with the answer the following is the code using HTTPClient

HttpClient client = new DefaultHttpClient(); 
            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);

Hope it helps some one..

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.