Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 100
Registered: ‎01-13-2011
My Device: Not Specified
Accepted Solution

post data to httpconnection http 302

I am tryind to send parameters via post to a httpconnection but always get http response code 302

 

this is my code:

HttpConnection conn = conn =  (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
URLEncodedPostData encoder = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
encoder.append("param1","value");
encoder.append(...);
conn.setRequestMethod( javax.microedition.io.HttpConnection.POST );
conn.setRequestProperty("Content-Length", String.valueOf(encoder.getBytes().length));
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream oStream;
oStream = conn.openOutputStream();
oStream.write( encoder.getBytes() );
oStream.flush();

 What is courious is that if I use a BrowserField2 I can connect without problem using this code:

 

BrowserField browserField = new BrowserField();
final MainScreen screen = new MainScreen();
screen.add(browserField);
String postData = "param1=value&aparam2=" ...;
Hashtable header = new Hashtable();
header.put("Content-Length", "" + postData.length());
header.put("Content-Type", "application/x-www-form-urlencoded");
String url = "http://...";
browserField.requestContent(url, postData.getBytes(), header);
UiApplication.getUiApplication().invokeLater(new Runnable() {
	public void run() {
		UiApplication app = UiApplication.getUiApplication();
		app.pushScreen(screen);
	}
});

 

The problem is that I net get return params and I do not know how to get them using browserField

 

 

Highlighted
Developer
Posts: 16,984
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: post data to httpconnection http 302

302 means content moved, most likely you have to issue the request again for the new url (get it from the header).
the browserfield probably follows the redirect by itself.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter