views:

41

answers:

1

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  A: 

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.

BalusC
OK - thanks - does the Apache client support the "*" parameter and how would I add it?
nzpcmad
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: http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/OptionsMethod.html#OptionsMethod%28java.lang.String%29
BalusC
On HttpClient 4.0 there's no OptionsMethod, it's rather HttpOptions class (http://hc.apache.org/httpcomponents-client/httpclient/apidocs/org/apache/http/client/methods/HttpOptions.html)
The Elite Gentleman
@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.
BalusC
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. :-)
The Elite Gentleman