HttpConnection - Bad request

[nobr]Hi all,

I am new to j2me and i am trying to connect my midlet through HttpConnection for accessing a text file from server. It works perfectly in my local server with apache tomcat.

My problem starts here, when i try to access the file from actual server (not localhost) the server responds with

<!DOCTYPE HTML PUBLIC"-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>400 Bad Request</title>

</head><body>

<h1>Bad Request</h1>

Your browser sent a request thatthis server could not understand.<br />

Additionally, a 400 Bad Request

error was encounteredwhile trying to use an ErrorDocument to handle the request.

</body></html>

The url is working in standard web browser. Is there any permission required from server so that client can communicate with HttpConnection ?[/nobr]

[1041 byte] By [Ajisha] at [2007-11-26 21:15:59]
# 1

Hi,

I found the solution, and the problem was server needs the User-Agent property to identify the agent. if anybody have similar type of connection errors like a 400 bad request error try adding setRequestMethod for the HttpConnection.

String url = "http://www.somehost.com/text.txt";

hc = (HttpConnection)Connector.open(url);

hc.setRequestMethod( HttpConnection.GET );

hc.setRequestProperty( "User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1" );

hc.setRequestProperty( "Accept", "text/txt" );

if you are trying to access an image, then change last line to

hc.setRequestProperty( "Accept", "image/png" );

Thankyou

Ajish

Ajisha at 2007-7-10 2:54:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Hi AjishI tried your solution but id did not work.I still get bad request, But whenever I put the txt file on different host I can read it. What could be the problem? Is it something to do with host configurations?
gerekbolsaa at 2007-7-10 2:54:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Try to add this propertyhttpCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
morreale.ga at 2007-7-10 2:54:33 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
2 morreale.g I tried but it did not work. But if I move the txt file to another server it works.And aslo it is working with emulator on both servers.I am confused.
gerekbolsaa at 2007-7-10 2:54:33 > top of Java-index,Java Mobility Forums,Java ME Technologies...