Reading URLs with POST data vs. w/out POST

H

Hal Vaughan

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/361...es/361003WorldSeriesGiantsVsYankees_files.xml>

Length reported as -1:
<http://www.archive.org/search.php?page=1&query=collection:oldtimeradio&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
 
A

Arne Vajhøj

Hal said:
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/361...es/361003WorldSeriesGiantsVsYankees_files.xml>

Length reported as -1:
<http://www.archive.org/search.php?page=1&query=collection:oldtimeradio&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.

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
 
M

Mark Space

Hal said:
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?
 
H

Hal Vaughan

Mark said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top