Skip to main content

getResponse returns -1

1 reply [Last post]
nisha_dh
Offline
Joined: 2010-07-30
Points: 0

Hii all,
Am havin a BIG problem here. I have two different method with different http connection methods in my midlet, accessing two different php files from the server.
For the first http connection, every thing goes fine, and i get right result.
but with the second one, (with similar code format), am getting this -1 value as the return value. And also
getResponseMessage() returns null.

Can anyone help me to solve the problem??
I have the code for the second method below:

public void getCafe(String imei, String answer, String tags_1, String tags_2, String tags_3, String tags_4, String tags_5 , String note_time)
throws IOException {
InputStream iS = null;
HttpConnection htp = null;
ByteArrayOutputStream bS = null;

String url = "http://localhost/mobile/majaxtags.php";

try {

url = url + "?note_time=" + note_time+"&imei=" + imei + "&tags1=" + tags_1 + "&tags2=" + tags_2
+ "&tags3=" + tags_3 + "&tags4=" + tags_4 + "&tags5=" + tags_5 + "&answer=" + answer ;

htp = (HttpConnection)Connector.open(url);
htp.setRequestMethod(HttpConnection.GET);
long i = htp.getLength(); //returns -1
int c = htp.getResponseCode(); //returns -1
String s = htp.getResponseMessage(); //returns null

if (htp.getResponseCode() == HttpConnection.HTTP_OK) {

int ch = 0;

iS = htp.openInputStream();
bS = new ByteArrayOutputStream();
while ((ch = iS.read()) != -1) {

bS.write(ch);

}

}

}finally {
if (iS != null) {
iS.close();
System.out.println("closed dt istrm ");
}
if (bS != null) {
bS.close();
System.out.println("closed dt bstrm ");
}

if (htp != null) {
htp.close();
System.out.println("closed dt http");
}

}
String cafeinfo = new String(bS.toString());
System.out.println("cafe info is: " + cafeinfo);
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nisha_dh
Offline
Joined: 2010-07-30
Points: 0

have already been able to solve the problem..hehee..used POST method in place of GET and changed the codes accordingly.....worked perfectly fine then:)