BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 04-06-2009, 09:10 PM   #1 (permalink)
New Member
Join Date: Dec 2008
Model: 7100T
Carrier: Tmobile
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in htttp connection

Please Login to Remove!

I am doing http connection in application. My MDS is working wll in my JDE 4.0 but yet it is giving wrong response code like 406 but it is working on my client pc when he has installed JDE 4.2 and visual studio but what i am thinking is what could be wrong in JDE .0

private String MakeGetRequest(String command)
//open the connection and extract the data
StreamConnection s = null;

HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
int rc;

String url = Url() + command;

String credentials = Credentials();

try {
c = (HttpConnection);
c.setRequestProperty("Connection", "Keep-Alive");
c.setRequestProperty("User-Agent", "test app");

c.setRequestProperty("Accept", "application/xml");
c.setRequestProperty("Content-Type", "application/xml");

c.setRequestProperty("Authorization", "Basic " + credentials);

os = c.openOutputStream();

// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
rc = c.getResponseCode();

System.out.println("Response code="+rc);
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);

is = c.openInputStream();
System.out.println("after in stream");
// Get the ContentType
String type = c.getType();
System.out.println("after in stream");

// Get the length and process the data
int len2 = (int)c.getLength();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

System.out.println("after in stream");

//byte[] buffer = new byte[256];
byte[] buffer = new byte[len2];
System.out.println("after in stream");;
int len = 0, imageSize = 0;

while (-1 != (len = {
imageSize += len;
System.out.println("after in stream");
String result = byteArrayOutputStream.toString();
System.out.println("after in stream="+result);

return result;

} catch (ClassCastException e) {
throw new IllegalArgumentException("Not an HTTP URL");

} catch (IOException e) {
throw new IllegalArgumentException("Not an HTTP URL");
catch(Exception e)

return null;

The following is my code for http.
Kartik Trivedi

(Sun Certified Java Developer)

(Forum Nokia Champion)

(Software Developer-J2ME)

(Saltriver Infosystem)

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