BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-07-2008, 06:59 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: pearl
PIN: N/A
Carrier: none
Posts: 20
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTPPOST IOException

Please Login to Remove!

Dear all,

So here is a httppost application tht i am using.I am trying to connect to the email form server as given below and then post data to it. However it seems to give me IOException cannot connect in the connector.open. I tried appending deviceside=false or true and it doesnt help.

Any input on what needs to be changed in order to make it work...

Btw my internet is working fine on the simulator. I tried the inbuilt browser and it gives me access. So MDS or simulator should not be the problem..

Code:
class ServerConnection extends Thread {

	HttpConnection httpConnection = null;
	InputStream httpInput = null;
	DataOutputStream httpOutput = null;
	String url = "http://www.emailmeform.com/fid.php?formid=108223";
	String serverResponse = "";
	String message;
	ConnectionExampleScreen screen;

	public ServerConnection(String message, ConnectionExampleScreen screen) {
		this.message = message;
		this.screen = screen;
	}

	public void run() {
		try {
			byte[] data = message.getBytes();
			int dataLength = data.length;
			if (url.indexOf("NOIPPP") > -1) {
				screen.updateDebugInfo("No IPPP Service Books found");
			} else {
				httpConnection = (HttpConnection)Connector.open(url);
				 int rc = httpConnection.getResponseCode();
		            if (rc != HttpConnection.HTTP_OK) {
		                throw new IOException("HTTP response code: " + rc);
		            }
httpConnection.setRequestProperty("enctype", "multipart/form-data");
				httpConnection.setRequestProperty("accept-charset","UTF-8");

				httpConnection.setRequestMethod(HttpConnection.POST);
				//httpConnection.setRequestProperty("Host", host);
				//httpConnection.setRequestProperty("Content-Length", Integer.toString(dataLength));
				//httpConnection.setRequestProperty("Expect", "100-continue");
				httpOutput = httpConnection.openDataOutputStream();
				httpOutput.write(data, 0, dataLength);
				httpInput = httpConnection.openInputStream();

				StringBuffer buffer = new StringBuffer();

				int ch = 0;
				while (ch != -1) {
					ch = httpInput.read();
					buffer.append((char) ch);
				}

				serverResponse = buffer.toString();
				screen.updateScreen(serverResponse);
			}
		} catch (IOException ex) {
			ex.printStackTrace();
			screen.updateScreen(ex.toString());
		}
	}
Offline  
Old 07-07-2008, 08:59 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: pearl
PIN: N/A
Carrier: none
Posts: 20
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

an update.. i tried running the program on the real device and it also gives me the same problem. Gives an IOException !
Offline  




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