• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Error Initializing http tunnel connection.  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i had written a simple program using j2me wireless toolkit 2.0 for http connection. and i got a runtime error as listed below.
java.io.IOException: Error initializing HTTP tunnel connection:
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/5.0
Date: Mon, 27 Jan 2003 10:56:14 GMT
Connection: close
Content-Length: 4009
Content-Type: text/html
at com.sun.midp.io.j2me.http.Protocol.doTunnelHandshake(+282)
at com.sun.midp.io.j2me.http.Protocol.connect(+119)
at com.sun.midp.io.j2me.http.Protocol.streamConnect(+44)
at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+6)
at com.sun.midp.io.j2me.http.Protocol.openInputStream(+9)
at HTTPMIDlet.sendGetRequest(+42)
at HTTPMIDlet.commandAction(+29)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+284)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
i am not sure of the cause of such an error and whether some settings have to be changed for http connectivity...
i would be glad if someone could help me out with this...
- Ajay
 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Could you please post the part of the code that is doing the connection to the server.
regards
vivek
 
Ajay Chakravarthi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
herez the entire code for the problem desc above.... i also have a proxy server running here for which i have made the appropriate changes in wtk proxy server settings....
would be nice if somebody could help me with it...
- Ajay
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class HTTPMIDlet extends MIDlet implements CommandListener {
private static String defaultURL =
"http://www.comp.polyu.edu.hk/~csstlee/hello.txt";
// GUI component for user to enter web url
private Display myDisplay = null;
private Form mainScreen;
private TextField requestField;
// GUI component for displaying web page content
private Form resultScreen;
private StringItem resultField;
// the "send" button used on mainScreen
Command sendCommand = new Command("SEND", Command.OK, 1);
// the "back" button used on resultScreen
Command backCommand = new Command("BACK", Command.OK, 1);
public HTTPMIDlet(){
// initializing the GUI components for entering web urls
myDisplay = Display.getDisplay(this);
mainScreen = new Form("Type in a URL:");
requestField =
new TextField(null, defaultURL,
100, TextField.URL);
mainScreen.append(requestField);
mainScreen.addCommand(sendCommand);
mainScreen.setCommandListener(this);
}
public void startApp() {
myDisplay.setCurrent(mainScreen);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
// when user clicks on "send" button on mainScreen
if (c == sendCommand) {
// retrieving the web url that user entered
String urlstring = requestField.getString();
System.out.println("hai 1");
// sending a GET request to web server
String resultstring = sendGetRequest(urlstring);
System.out.println("hai 2");
// displaying the page content retrieved from web server
resultScreen = new Form("GET Result:");
resultField =
new StringItem(null, resultstring);
resultScreen.append(resultField);
resultScreen.addCommand(backCommand);
resultScreen.setCommandListener(this);
myDisplay.setCurrent(resultScreen);
} else if (c == backCommand) {
// do it all over again
requestField.setString(defaultURL);
myDisplay.setCurrent(mainScreen);
}
}
// send a GET request to web server
public String sendGetRequest(String urlstring) {
HttpConnection hc = null;
DataInputStream dis = null;
String message = "";
try {
/* openning up http connection with the web server
* when the connection is opened, the default request
* method is GET
*/
System.out.println(urlstring);
hc = (HttpConnection)
Connector.open(urlstring);
hc.setRequestMethod(HttpConnection.GET);
hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
hc.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
hc.setRequestProperty("Content-Language", "en-US");
hc.setRequestProperty("Accept", "application/octet-stream");
hc.setRequestProperty("Connection", "close"); // optional property
int rc = hc.getResponseCode();

if (rc != HttpConnection.HTTP_OK) {
System.out.println("Error. HTTP response code: " + rc);
}
// establishing input stream from the connection
dis = new DataInputStream(hc.openInputStream());

// reading the response from web server character by character
int ch;
while ((ch = dis.read()) != -1) {
message = message + (char) ch;
}
}
catch (InterruptedIOException cnf) {System.out.println("Interrupted IO");}
catch (EOFException cnf) {System.out.println("EOF");}
catch (IOException ioe) {
System.out.println("IO Exception");
ioe.printStackTrace();
message = "ERROR";
} finally {
try { if (hc != null) hc.close();} catch (IOException ignored) {}
try { if (dis != null) dis.close();} catch (IOException ignored) {}
}
return message;
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!