HTTP is Hypertext Transfer Protocol. It is a protocol developed to transfer web pages from a http server such as apache or IIS to a browser. HTTP is also now used to transfer other things as well, such as images, xml files, etc... Another example of a protocol is FTP or File Transfer Protocol. Neither was developed specifically to bypass corporate firewalls.
As a rule of thumb I would say use URLs when you can, and Sockets when you can't use URLs.
It looks like this code either connects to the remote host or to the remote proxy, though it never sends anything to the proxy to indicate that it should forward the connection to the remote host. Also, I don't know why the program insists on specifying the local address and port. The comments indicate that this is an HTTP proxy, so to use it (without specifically connecting to the proxy and using it's protocol directly) you may want to set the following properties: http.proxySet=true http.proxyHost=proxyAddress http.proxyPort=proxyPort And then use a URLConnection with the remote host address. It will automatically use the HTTP proxy.
Thanks for your response. I guess I have a problem with the authentication though.
gives me the error java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.marchal.com/ at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:709) at net1.url2.URLTrial.main(URLTrial.java:43) Server returned HTTP response code: 407 for URL: http://www.marchal.com/
I think this has to do with authorizing the server. Can you please include the statement to authorize in my code, Thanks, Divya
At this point I would encourage you to read the documentation for both HttpClient and JBuilder. I have never used JBuilder, and I do not recall if you only need to download HttpClient jars or if other jakarta jars are also required, but I do know that it's all covered in the scant documentation. Chris
Hi Chris, I could configure my Jbuilder to use the Jakarta HttpClient. I'm able to connect to the web site and the proxy authenticated with no problems for the Web page that doesn't send a cookie. But for the page that sends a cookie, it gives me the following error. Oct 8, 2003 1:12:14 PM org.apache.commons.httpclient.HttpMethodBase processAuthenticationResponse INFO: Already tried to authenticate to "courtgate.coca.co.clark.nv.us#" but still receiving 407. <HTML> <HEAD><TITLE>407 Proxy Authentication Required</TITLE></HEAD> <BODY> <H1>Proxy Authentication Required</H1> <H4> Unable to complete request:<P> Access denied due to authentication failure.
</H4> <HR> </BODY> </HTML> Any ideas? Thanks for helping me so far, Divya
Hmm... Well at least it's partly solved. I'm not sure why cookies would be a problem though. I must admit I have never tried using an authenticating proxy server with a java client, so I have not run into this problem. You may want to ask this question on the Jakarta Commons user email list or developer email list. The mailing list archives can also be searched, though a quick search I did, didn't reveal exactly this problem. I'm sure they would be happy to receive your input and fix it if it turns out to be a bug. Chris
I've just subscribed to the mailing list of JakartaCommonsHTTPClient. thnaks for the suggestion. I wonder why didn't I do this before!!! well, looks like it's gong to take some time before they answer me though. In the mean time can you throw some light on how can I modify my code to recieve and send a cookie through HTTPClient. I mean I went through the documentation but was of no help. Thanks, Divya
I don't think a seperate package is necessary to provide proxy authentication support to your app. You can use any base64 encoder to encode proxy username and password.And put this value for Proxy-authorization request property.There are lot of base64 encoders available. sun VM has one in sun.misc package.
Hmm... It may be that you don't need HttpClient after all. As I was looking for Base64 encoding, I came across java.net.Authenticator. It looks like you may be able to create a proxy password authenticator and use it as the default authenticator for the proxy. This code snippet might work:
I have not tried that code, but something like it might work. Chris
Chris, I suceeded with the proxy with the simple HttpConnection. I did exactly what you guys have suggested. Authenticator.setDefault(new SimpleAuthenticator(username, password)); Properties systemProperties = System.getProperties(); systemProperties.setProperty("http.proxyHost", proxy); systemProperties.setProperty("http.proxyPort", port); But my problem is to capture the cookie and send it to the website. Like say I capture the cookies in a vector and send the last recent cookie when I access the website again to keep track of my sessions. Thanks, Divya
Evacuate the building! Here, take this tiny ad with you: