I have the following PC java code that works:
URL ulr0 = new URL ("...");
HttpsURLConnection con0 = (HttpsURLConnection)
url0.openConnection();
con0.setRequestMethod( "POST" );
con0.setUseCaches( false );
con0.setDoInput( true );
con0.setDoOutput( true );
con0.addRequestProperty ( "Cookie",
"BrowserTest=Success?;version=1" );
OutputStream out0 = con0.getOutputStream();
String toOut = "login=" + userid + "&" + ...
out0.write( toOut.getBytes() );
out0.flush();
String ret = getContent( con0.getInputStream(),
con0.getContentLength() );
con0.disconnect();
This is my MIDP translation:
String url0 = new String("...");
HttpsConnection c = null;
InputStream is = null;
OutputStream os = null;
c = (HttpsConnection)Connector.open(url0);
c.setRequestMethod( HttpsConnection.POST );
c.setRequestProperty
( "Cookie", "BrowserTest=Success?;version=1" );
os = c.openOutputStream();
String toOut = "login=" + userid + "&" + ...;
os.write( toOut.getBytes() );
os.flush();
int rc;
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK)
{
os.close();
c.close();
throw new Exception("Cannot send message to passport
server");
}
is = c.openInputStream();
StringBuffer sb = new StringBuffer();
sb.setLength(0);
int ch;
while ((ch = is.read()) != -1)
{
sb.append((char)ch);
}
is.close();
os.close();
c.close();
String ret = new String(sb);
It does not work: the getResponseCode() function returns code 500 (internal server error). What's wrong with my code?

Reply With Quote

