[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3911
  • Last Modified:

setting http/1.0 protcol in the HttpURLConnection

I want to set http/1.0 protocol in the HttpURLConnection that i create.

Is there any method in HttpURLConnection, that an be used to do so.

Thanking in advance

cheers
Suddu,
0
sudarshan_sharma22
Asked:
sudarshan_sharma22
  • 4
  • 2
  • 2
  • +3
1 Solution
 
ramazanyichCommented:
no. It is hardcoded into implementation sun.net.www.protocol.http.HttpURLConnection
0
 
zzynxSoftware engineerCommented:
See http://micro5.mscc.huji.ac.il/~aries/net2.html
Search for: "Start sending our reply, using the HTTP 1.0 protocol"
0
 
ajvedCommented:
Do not need to connect a packet.... need to use HttpURLConnection or objects as such :(
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sudhakar_koundinyaCommented:
ignore previous statement
0
 
ramazanyichCommented:
http://www.innovation.ch/java/HTTPClient/getting_started.html

An HttpURLConnection class and the necessary URLStreamHandlers are provided so that you may easily replace the JDK's HttpClient with the HTTPClient. All you need to do is define the java system property java.protocol.handler.pkgs as HTTPClient. For example, on the command line this would look like

    java -Djava.protocol.handler.pkgs=HTTPClient MyApp

Invoking URL.openConnection() will then return an instance of HTTPClient.HttpURLConnection.

Note that there are a couple small differences compared to Sun's HttpClient when POSTing - please see the class documentation for more information.
0
 
ramazanyichCommented:
addition to my previous message: you can force HTTP/1.0 request by setting -DHTTPClient.forceHTTP_1.0=true proeprty to you JVM. So your call to your application will be:
java -classpath HTTPClient.jar  -Djava.protocol.handler.pkgs=HTTPClient  -DHTTPClient.forceHTTP_1.0=true MyAPP
0
 
sudarshan_sharma22Author Commented:
Venabili, Sorry for the caused confusion.

We Aren't the same person,

Bu we know each other and thats something which he was also looking for and i adviced him to observe this thread which would be helpful for him too.

The comment added by him is something is what he is looking for.

Regards,
Suddu.






0
 
zzynxSoftware engineerCommented:
>> i adviced him to observe this thread
To avoid any confusion in the future, when he adds comments like this, let him first mention in the comment
- that he is not the author
- but that he is a colleague interested in the same solution
0
 
ajvedCommented:
zzynx,

Thanks for the suggestion, henceforth i will ensure that i add these as the comments while trailing the thread.

regards
0
 
VenabiliCommented:
I would advice you NOT to use this thread for your own question but to ask a separate one (or if it is the same trouble to leave the Asker to respond here). Otherwise it is a missuse of the points system(using  questions from other people )

Venabili
0
 
sudarshan_sharma22Author Commented:
I followed the steps given by ramazanyich. I was  hitting to a jsp in Resin. BY using getProtocol i got http1.1.

Am yet to find a soln. Seems like java has hard coded to use http1.0 protocol.

Regards,
Sudarshan
0
 
ramazanyichCommented:
to check that browser sent really HTTP/1.0 request you choose wrong method. Better use some network  monitoring tools. I used Ethereal (www.ethereal.org) and used my solution.
I wrote simple program:
public class HttpTest {
   
    public static void main(String[] args) {
        try{
        URL url = new URL(args[0]);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
       
        System.out.println(conn.getContent());
        System.out.println(conn.getResponseCode());
        }catch(Exception e){
            e.printStackTrace();
        }
       
    }

}

I started Ethereal and execuited my program with HTTPClient:
java -classpath c:\distr\HTTPClient.zip;bin  -Djava.protocol.handler.pkgs=HTTPClient  -DHTTPClient.forceHTTP_1.0=true  HttpTest http://www.microsoft.com

And I got follwoing on ethereal:

GET / HTTP/1.0
Host: www.microsoft.com
Connection: Keep-Alive, TE
TE: trailers, deflate, gzip, compress
User-Agent: RPT-HTTPClient/0.3-3
Accept-Encoding: deflate, gzip, x-gzip, compress, x-compress

HTTP/1.1 200 OK
Cache-Control: public
Content-Length: 13300
Content-Type: text/html
....
As you can see browser sent HTTP/1.0 request.,
but server replied with HTTP/1.1

And if I don't use HTTPClient then I got follwoing in Ethereal:
GET / HTTP/1.1
User-Agent: Java/1.4.2_06
Host: www.microsoft.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

HTTP/1.1 200 OK
Cache-Control: public
Content-Length: 13300
Content-Type: text/html
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now