BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-06-2009, 09:10 PM   #1
honestsuccess
New Member
 
Join Date: Dec 2008
Model: 7100T
PIN: N/A
Carrier: Tmobile
Posts: 14
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;
System.out.println(url);


String credentials = Credentials();
System.out.println(credentials);

try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.GET);
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");
is.read(buffer);
byteArrayOutputStream.write(buffer);
/*
int len = 0, imageSize = 0;

while (-1 != (len = is.read(buffer))) {
byteArrayOutputStream.write(buffer);
imageSize += len;
}
*/
byteArrayOutputStream.flush();
System.out.println("after in stream");
String result = byteArrayOutputStream.toString();
System.out.println("after in stream="+result);
byteArrayOutputStream.close();

return result;

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

} catch (IOException e) {
System.out.println(e.toString());
throw new IllegalArgumentException("Not an HTTP URL");
}
catch(Exception e)
{
System.out.println(e.toString());
}
finally
{

}
return null;
}


The following is my code for http.
__________________
Kartik Trivedi

(Sun Certified Java Developer)

(Forum Nokia Champion)

(Software Developer-J2ME)

(Saltriver Infosystem)
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


USB BIOS EEPROM SPI FLASH Programmer CH341A 24 25 series BIOS Writer Burner Chip picture

USB BIOS EEPROM SPI FLASH Programmer CH341A 24 25 series BIOS Writer Burner Chip

$7.57



CH341A 24 25 Series EEPROM Flash BIOS USB Programmer Module + SOIC8 Test Clip picture

CH341A 24 25 Series EEPROM Flash BIOS USB Programmer Module + SOIC8 Test Clip

$5.88



10PCS DIP-28 Eeproms Programmable Flash Chip For SST27SF512-70-3C-PG SST 27SF512 picture

10PCS DIP-28 Eeproms Programmable Flash Chip For SST27SF512-70-3C-PG SST 27SF512

$27.89



5PCS EEPROM IC ATMEL DIP-28 AT28C256 AT28C256-15PU US picture

5PCS EEPROM IC ATMEL DIP-28 AT28C256 AT28C256-15PU US

$33.99



Eeprom Bios Usb Programador Ch341a + Soic8 Clip + 1.8V Adaptador + Soic8 Ada picture

Eeprom Bios Usb Programador Ch341a + Soic8 Clip + 1.8V Adaptador + Soic8 Ada

$23.15



10PCS For SST27SF512-70-3C-PG SST 27SF512 DIP-28 Eeproms Programmable Flash Chip picture

10PCS For SST27SF512-70-3C-PG SST 27SF512 DIP-28 Eeproms Programmable Flash Chip

$27.69







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