Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Reading URLs with POST data vs. w/out POST

Thread view: 
Hal Vaughan - 12 Jan 2008 03:49 GMT
I'm working a simple method to read web pages and experimenting with a few
aspects.

I've noticed if the URL contains POST data (and I'm just specifying the POST
data in the URL), when I try URLConnection().getContentLength(), I often
get a length of -1.  I don't see this happen on any web pages without any
post data.

Is this because the page is generated dynamically and the server may not be
reporting the length for a posted page but is reporting it for a static
page?

I've tested different configurations in programs and even copied different
examples from web pages to test this out, but the effect is code
independent.

Here are two example pages:

Length reported correctly:
<http://www.archive.org/download/361003WorldSeriesGiantsVsYankees/361003WorldSeri
esGiantsVsYankees_files.xml
>

Length reported as -1:
<http://www.archive.org/search.php?page=1&query=collection%3Aoldtimeradio&sort=title>

I don't think this is a Java language issue, but more a factor of what data
one gets back from a server.  Am I right about this?  Is it a server issue?
The server, according to Netcraft, is running Apache.

Hal
Arne Vajhøj - 12 Jan 2008 04:18 GMT
> I'm working a simple method to read web pages and experimenting with a few
> aspects.
[quoted text clipped - 23 lines]
> one gets back from a server.  Am I right about this?  Is it a server issue?
> The server, according to Netcraft, is running Apache.

When you talk about "URL contains POST data" I assume that you means
"URL with query string" (the data in a POST is not in the URL !).

Java docs for getContentLength() says:

#Returns:
#    the content length of the resource that this connection's URL
#       references, or -1 if the content length is not known.

The HTTP standard says about Content-Length header:

#                                                          In HTTP, it
#   SHOULD be sent whenever the message's length can be determined prior
#   to being transferred, unless...

It sounds very plausible that:
  * the byte count can easily be detected for static content
  * the byte count can not as easily be detected for scripts

Arne
Mark Space - 12 Jan 2008 22:02 GMT
> I'm working a simple method to read web pages and experimenting with a few
> aspects.

What happened to your last issue with setFocusableWindowState()?  Did
you get it working?
Hal Vaughan - 14 Jan 2008 00:38 GMT
>> I'm working a simple method to read web pages and experimenting with a
>> few aspects.
>
> What happened to your last issue with setFocusableWindowState()?  Did
> you get it working?

I had to set it aside for a bit and will be looking at that thread and that
issue in a day or so.  That was more a cosmetic issue and I figured it was
more important to make sure everything was working properly before worrying
about UI issues.

Hal
Roedy Green - 13 Jan 2008 11:02 GMT
>Is this because the page is generated dynamically and the server may not be
>reporting the length for a posted page but is reporting it for a static
>page?

That is so, and often it is just left out presumably out of laziness.
See my code for
GET and POST at http://mindprod.com/products.html#HTTP
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.