• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error code 501- urgent

 
Sonal Jogi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

While trying to connect to a server using HttpURLConnection, I am geting 501 error. If i paste the same URL in the browser and exceute it, it gives me the result. As I am behind a proxy server, i am doing the proxy server settings also. Could anybody please tell me what wrong i could be doing?


String sURLString ="http://www.google.com/search?q=Check+Venetian+Resort+Hotel+Hotels+FLIGHT&adtest=on&client=xxxxx&ad=w2n10";
String sProxyHosts = "", sProxyPort="";
sProxyHosts = "116.160.254.12";//sample proxy server ip address
sProxyPort = "8080";//port no
Properties props = System.getProperties();
props.put("http.proxyHost", sProxyHosts);
props.put("http.proxyPort", sProxyPort);
System.setProperties(props);

URL sUrl = new URL (sURLString);
HttpURLConnection httpConnection = (HttpURLConnection) sUrl.openConnection();
httpConnection.setDoOutput (true);
httpConnection.setDoInput(true);
httpConnection.setRequestProperty("Content-type", "text/xml");
httpConnection.setRequestMethod ("GET");

PrintWriter printWriter = new PrintWriter (httpConnection.getOutputStream ());
printWriter.flush ();
printWriter.close();
httpConnection.connect();

Thanks in advance,
sonal
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a proxy, so I can't test that. Near as I can tell you are doing two connects. httpConnection.getOutputStream will force a connect, then you explicity invoke connect(). The explicit call is the one that throws the exception. HTTP error code 501 means " The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource." HTTP Status Codes
So I removed the code both the PrintWriter code and the explicit connect and get a 403 ("The server understood the request, but is refusing to fulfill it"). I'm beginning to think that Google refuses to server non-browser clients (Disclaimer: wild speculation). Perhaps you should look at the various
Google API's, particularly the SOAP API for web searches.
 
Sonal Jogi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes, you are absolutely right. I had come to the same conclusion and had worked it out. When i removed the printwriter statements and connect() function, it worked perfectly.

But thanks a lot for the prompt reply,
Thanks,
sonal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!