BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-07-2008, 07: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, 09: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  
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.