E
Endi
Hi all,
does anybody know a solution to this:
I try to write data from a handheld via http to a webserver. But
somehow the server seems to ignore my OutputStream. I can open the
connection and receive the response, but when I try to write something
the server sends no response. The function getResponseCode() gives me a
200 but in the next step the InputStream is empty. I can send the post
command "POST http://1.10.1.5/webtest.nsf/Zaehler?CreateDocument
Http/1.1" via telnet and the server works fine but not from the
handheld. Please help. Thanks in advance.
Regards
Andreas
try{
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
int rc;
try {
c = (HttpConnection)Connector.open("http://10.10.1.5");
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("If-Modified-Since",
"29 Oct 1999 19:43:31 GMT");
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
c.setRequestProperty("Host", "10.10.1.5");
c.setRequestProperty("Accept", "text/html");
c.setRequestProperty("Connection", "close");
String s =
"http://1.10.1.5/webtest.nsf/Zaehler?CreateDocument";
int l = s.length();
StringBuffer sb = new StringBuffer();
sb.append(l);
c.setRequestProperty("Content-Length", sb.toString() );
is = c.openInputStream();
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
int len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
// process(data);
} else {
int ch;
while ((ch = is.read()) != -1) {
// process((byte)ch);
}
}
os = c.openOutputStream();
os.write(s.getBytes());
os.flush();
rc = 0;
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
// process(data);
} else {
int ch;
while ((ch = is.read()) != -1) {
// process((byte)ch);
}
}
} catch (ClassCastException e) {...
does anybody know a solution to this:
I try to write data from a handheld via http to a webserver. But
somehow the server seems to ignore my OutputStream. I can open the
connection and receive the response, but when I try to write something
the server sends no response. The function getResponseCode() gives me a
200 but in the next step the InputStream is empty. I can send the post
command "POST http://1.10.1.5/webtest.nsf/Zaehler?CreateDocument
Http/1.1" via telnet and the server works fine but not from the
handheld. Please help. Thanks in advance.
Regards
Andreas
try{
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
int rc;
try {
c = (HttpConnection)Connector.open("http://10.10.1.5");
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("If-Modified-Since",
"29 Oct 1999 19:43:31 GMT");
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
c.setRequestProperty("Host", "10.10.1.5");
c.setRequestProperty("Accept", "text/html");
c.setRequestProperty("Connection", "close");
String s =
"http://1.10.1.5/webtest.nsf/Zaehler?CreateDocument";
int l = s.length();
StringBuffer sb = new StringBuffer();
sb.append(l);
c.setRequestProperty("Content-Length", sb.toString() );
is = c.openInputStream();
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
int len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
// process(data);
} else {
int ch;
while ((ch = is.read()) != -1) {
// process((byte)ch);
}
}
os = c.openOutputStream();
os.write(s.getBytes());
os.flush();
rc = 0;
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
// process(data);
} else {
int ch;
while ((ch = is.read()) != -1) {
// process((byte)ch);
}
}
} catch (ClassCastException e) {...