GeeCON Prague 2014*
The moose likes Sockets and Internet Protocols and the fly likes HTTP Response code 414 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HTTP Response code 414 " Watch "HTTP Response code 414 " New topic
Author

HTTP Response code 414

khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
Hi,

Could some one help me out here,I am getting 414 Request error -URI too long ,The Server is refusing to service the request because the requested URI is too long.Can I know how can can I overcome this error?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Shorten your URI


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you submitting a form with method="get" or no method attribute?
If so, the browser will try to put the entire contents of the form in the querystring.
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
There is no method(get/post) attribute,I am using
HttpURLConnection httpConn = (HttpURLConnection) ((new URL(url).openConnection())); in order to go to that url.and the server is is refusing to service the request because the requested URL is too long and our HTTP server can take upto 8KB.
[ March 13, 2008: Message edited by: khan ahamad ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why is your URL so long?
Are you building up a huge query string?
If so, why not create an HTTP Post request and send the data as part of the request body?
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
Yes the url is too long..I am not using IE to make the URL call, but I am making an HttpURLConnection with our Java code.So is it possible to use POST method in this case?
[ March 14, 2008: Message edited by: khan ahamad ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by khan ahamad:
... So is it possible to use POST method in this case?


Yes, there is a code sample that does just that in this thread:
http://www.coderanch.com/t/278906/Streams/java/HTTP-POST-does-vanilla-web
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by khan ahamad:
(...snip...)So is it possible to use POST method in this case?


Yes, and in general POST method is to be preferred over GET because of not exposing session data to uninfomed users. I am working on something very close to this right now and have a design idea of a few name=value pairs in the address-bar, but not much and nothing along the lines of url-encoding that ends up with many %20%20 and so on in the request string.
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
can the other solution to this problem be splliting up the calls
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
You will have to code 'split the calls' - I am sure you intend to write name/value pairs in the viewable url. An attempt to code this will tell us what approach you are considering.
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
No, I dont mind displaying name/value in url
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What don't you want to send the data in the body with the post method?
That sounds like the easiest and most stable way to do this.
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
I implemented post method but still I am getting the same error HTTP 414, I am not able to make out why that is happening
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How long is the URL?
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
URL is exceeding 8K and the server which accepts this URL has 8K limit.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
What package are you using?
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
HttpURLConnection httpConn = (HttpURLConnection) ((new URL(URL).openConnection()));
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're sending the data in a post string, the URL should no longer need to be very large.
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
Yes , As I am sending data in post method I am splitting the URL
URL=actual url without parameter(that is upto "?" mark)
URLParam=URl's parameter (that is (name=value)

HttpURLConnection httpConn = (HttpURLConnection) ((new URL(URL).openConnection()));
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
OutputStream os = con.getOutputStream();
httpConn.setRequestProperty(URLParam.length());
httpConn.connect();
khan ahamad
Greenhorn

Joined: Mar 13, 2008
Posts: 11
please can anyone help me?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're sending the data in the post, you shouldn't need a '?' symbol or any name=value pairs in your URL.

What does your URL look like?
 
GeeCON Prague 2014
 
subject: HTTP Response code 414