Cannot get J2ME HTTP POST to work

Hi,

Can someone tell me why this code is not working. I am using JBuilder2006 with integrated Sun wireless toolkit, the latest version I believe. I am using a simple Tomcat JSP page to read the POST and send a response.  

GET operations work fine. But on the POST, the jsp recieves the request but the post body is not making it through. The jsp does report that the request type as post. The username and password parameters are null within the JSP.

Please help!

HttpConnection c = (HttpConnection)Connector.open("http://localhost:8080/WebModule2/jsp1.jsp",Connector.READ_WRITE);
String content = "username=beta&password=tester\r\n";
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = c.openOutputStream();
os.write(content.getBytes());
os.flush();
os.close();
   
StringBuffer sb = new StringBuffer();
InputStream is = c.openDataInputStream();
byte b[] = new byte[1024];
int cnt = 0;
long ts = System.currentTimeMillis();
while ( cnt > 0 || System.currentTimeMillis()-ts < 3000)
{
   cnt = is.read(b,0,b.length);
   if(cnt>0)
   {
     sb.append(new String(b,0,cnt));
     ts = System.currentTimeMillis();
   }
}
 response = sb.toString();
LVL 3
dgbwebAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bgloddeCommented:
With a GET request, you don't have to send extra info, but with a POST, you have some extra requirements.
I'm assuming you are already launching this in it's own Thread, outside of the main thread, since your GETs are working.
Let's try setting the content-length of the POST first...

String clen = Integer.toString(content.length());
c.setRequestProperty("Content-length", clen);

See if that allows the body to return.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgbwebAuthor Commented:
that fixed it

Thanks.

I have another question (see separate post for more points :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Wireless Networking

From novice to tech pro — start learning today.