> Hi all,
>
[quoted text clipped - 12 lines]
>
> Andreas
I think you try to send data to a closed connection. In your code, you
set the property:
> c.setRequestProperty("Connection", "close");
This means that the server will close the connection as soon as it has
sent its data.
You should try to use
> c.setRequestProperty("Connection", "Keep-Alive");
(not sure the syntax)
instead.
Additionally, can you tell what is in the "s" String that you want to
write back to the server?
> os = c.openOutputStream();
> os.write(s.getBytes());
> os.flush();
If the connection is set to stay open, you can reuse it to send a HTTP
formatted request. That means the "s" String has to be a valid HTTP
request (GET, POST, CGI, ...), or else the server will return an
"HTTP/1.1 400 Bad Request" response.
Hope this help
--
JSC
Endi - 16 Jun 2005 15:05 GMT
Hi JScoobyCed,
thanx for your reply. I had the Keep-Alive parameter for the connection
before. And it didn't work either. The s String contains the post
commands that will be sent to a server when you click the submit button
of the following html-file:
<html><body>
<form method="post"
action="http://10.10.1.5/webtest.nsf/V_Zaehler/Z1?SaveDocument"
name="_Zaehler">
<input name="Vorname" value="www">
<input type="submit" value="">
</form></body></html>
I thought what I write to the outputstreams are the post commands that
the server expects when you click on the submit button of a form. But I
think I am wrong.
Andreas
Darryl Pierce - 26 Jun 2005 15:17 GMT
> thanx for your reply. I had the Keep-Alive parameter for the connection
> before. And it didn't work either. The s String contains the post
> commands that will be sent to a server when you click the submit button
> of the following html-file:
You're doing your entire connection wrong. You should:
1. Create an HttpConnection object using Connector.open(String)
2. Define the request parameters, including content type and length
3. Open the output stream on the connection to write your data
4. Call the connection's getResponseCode() method, which will send the
request to the server and get the response
5. Call the connections getInputStream() method to retrieve the data
from the response
6. If you need to do another round trip with the server, go to step 1.
above and create a *new* HttpConnection object. The underlying
implementation will re-use the *physical connection* to the server if
that's an option. You *cannot* reuse your HttpConnection object to do a
second roundtrip with the server.

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard
Darryl Pierce - 26 Jun 2005 15:15 GMT
> I think you try to send data to a closed connection. In your code, you
> set the property:
[quoted text clipped - 5 lines]
> (not sure the syntax)
> instead.
No need for that. If you don't set a Connection property, then *by
default* it's set to keep-alive (MIDP uses a subset of HTTP 1.1, which
has persistent connections by default).
> Additionally, can you tell what is in the "s" String that you want to
> write back to the server?
[quoted text clipped - 4 lines]
> If the connection is set to stay open, you can reuse it to send a HTTP
> formatted request.
But, you cannot reuse the HttpConnection *object*. It's a stateful
object that, once it's received its request, cannot be reused to send
another request.

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard
<snip>
You're opening the input stream before it's been realized. You can only
open it *after* you're gotten the response code from the server. ANd,
you've never written anything to the *OUTPUT STREAM* for your request,
so no data was ever sent to the server.

Signature
Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard