BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-06-2009, 07:40 PM   #1 (permalink)
Knows Where the Search Button Is
 
ComputerWolf's Avatar
 
Join Date: Jul 2009
Model: 8310
PIN: N/A
Carrier: AT&T
Posts: 19
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Post to url problem

Please Login to Remove!

I am trying post some data to a url on my server, however the server is only coming back with an empty array instead of what I thought was posted. I am probably missing something, but I am unsure what.

Code:
HttpConnection oCon = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
oCon.setRequestMethod("POST");
URLEncodedPostData oPostData = new URLEncodedPostData(url, false);
oPostData.append("param1", "ThisIsTheValueOfParam1");
oPostData.append("param2", "ABC123");
OutputStream strmOut = oCon.openOutputStream();
strmOut.write(oPostData.getBytes());
strmOut.close();
The connection is fine and I get the response from the server, but apparently nothing is posted. Thanks.
Offline  
Old 07-14-2009, 04:06 AM   #2 (permalink)
New Member
 
Join Date: Jul 2009
Model: 7100T
PIN: N/A
Carrier: N/A
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not 100% sure about it, but i guess you should not close the Stream. Instead Flush it ;)

use 'strmOut.Flush();' instead of 'strmOut.close();'
Offline  
Old 07-14-2009, 08:35 AM   #3 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've seen some instances whereby if you don't open up an input stream after writing out, it won't finalize the stream and complete the POST. try that and see if it works
Offline  
Old 07-14-2009, 08:47 AM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

How about calling getReponse() (before calling close) - this flushes the buffers and retrieves the HTTP response from the server.
Offline  
Old 07-19-2009, 08:25 PM   #5 (permalink)
Knows Where the Search Button Is
 
ComputerWolf's Avatar
 
Join Date: Jul 2009
Model: 8310
PIN: N/A
Carrier: AT&T
Posts: 19
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just to let you know, I had to have this to get it to work:

Code:
String type = "application/x-www-form-urlencoded";
oCon.setRequestMethod(HttpConnection.POST);
oCon.setRequestProperty("Content-Type", type );
oCon.setRequestProperty("Content-Length", String.valueOf(oPostData.getBytes().length));
oCon.setRequestProperty("Content-Language", "en-US");
Thanks for the help!
Offline  
Old 07-20-2009, 06:50 AM   #6 (permalink)
Thumbs Must Hurt
 
shraddha294's Avatar
 
Join Date: Oct 2007
Location: Hyderabad
Model: 8800
PIN: N/A
Carrier: TMobile
Posts: 111
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good of you to post the resolution of ur query....
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.