Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileNotFoundException when accessing an ASP page with URL class

0 views
Skip to first unread message

Bryant Noice

unread,
Aug 30, 2001, 5:22:59 PM8/30/01
to
Hi,

I'm trying to access an ASP page via it's URL with the URL class. My
code looks like this:

Reader read = new InputStreamReader(new
URL(ASP_URL_STRING).openStream());
char[] buff = new char[4096];
while((len = read.read(buff)) != -1)
{
sFileContents += new String(buff, 0, len);
}

The url string (ASP_URL_STRING above) has an extensive query section
to it. If I issue the request just to the page ref (i.e.
http://server/page.asp) then I get the results just fine. If I issue
the request with just one or two of the query parameters (i.e.
http://server/page.asp?parm1&parm2), I get the results fine. However,
when I add the third (and largest) query parameter string to the URL,
it blows up, returning a FileNotFoundException. Checking the
getResponseCode() and getResponseMessage() methods on the
HttpURLConnection object yields "400 Bad Request". However, if I
simply place the full URL into the address bar of my browser, I get
the correct results, so it can't be a "bad request". The full URL is
about 400 characters.

I've tried every transformation/encode/decode/gyration offered in the
java.net package and am at wits end. Anybody seen this before and
have a good solution?

Thanks,

Bryant

Jon Skeet

unread,
Aug 30, 2001, 6:07:12 PM8/30/01
to

Although I can't find anything in the RFCs about it, URLs over 256
characters may be troublesome with some servers (or clients). If
possible, you should use POST parameters instead for that size of data.

Also, your loop is extremely inefficient. String += is almost *never* a
good thing to do - use a StringBuffer and call its append method
instead.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

0 new messages