BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   problem in http Connection with setRequestPRoperty() (http://www.blackberryforums.com/developer-forum/183077-problem-http-connection-setrequestproperty.html)

honestsuccess 03-26-2009 12:39 AM

problem in http Connection with setRequestPRoperty()
 
Whenever i am using setRequestProperty() in JDE 4.0 it is not working in my application. Giving exception time out. It was working weel in JDE 4.2. Can some one tell me what could be wrong in it ?

Ananthasivan V K 03-26-2009 12:57 AM

Quote:

Originally Posted by honestsuccess (Post 1333147)
Whenever i am using setRequestProperty() in JDE 4.0 it is not working in my application. Giving exception time out. It was working weel in JDE 4.2. Can some one tell me what could be wrong in it ?

Please paste the code segment that you used, what are you doing inside it ?

honestsuccess 03-26-2009 01:42 AM

Quote:

Originally Posted by Ananthasivan V K (Post 1333152)
Please paste the code segment that you used, what are you doing inside it ?


The following is code. take a look at it and plesae let me know if you find any thing wrong in it.

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)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();

if (rc != HttpConnection.HTTP_OK) {

throw new IOException("HTTP response code: " + rc);

}



is = c.openInputStream();



// Get the ContentType

String type = c.getType();



// Get the length and process the data

int len2 = (int)c.getLength();

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();



//byte[] buffer = new byte[256];

byte[] buffer = new byte[len2];

is.read(buffer);

byteArrayOutputStream.write(buffer);

/*

int len = 0, imageSize = 0;



while (-1 != (len = is.read(buffer))) {

byteArrayOutputStream.write(buffer);

imageSize += len;

}

*/

byteArrayOutputStream.flush();

String result = byteArrayOutputStream.toString();

byteArrayOutputStream.close();



return result;



} catch (ClassCastException e) {

throw new IllegalArgumentException("Not an HTTP URL");

} catch (IOException e) {

throw new IllegalArgumentException("Not an HTTP URL");

} finally {

}

}

Ananthasivan V K 03-26-2009 06:40 AM

Hi
 
Hi Karthik

I guess some of the property you specified is not correct, Have you tried without specifying those request properties ? Also the Authentication you specified I guess its not the exact way to give the same. Please try a simple request, then go for full fledged one.

honestsuccess 03-26-2009 02:12 PM

MDS and http connection
 
Is there necessary to use MDS ? One person told me that you are getting this exception "
Excepttion-java.io.InterruptedIOException: Local connection timed out after ~ 120000". One person told me that you must use MDS. Am i getting this exception because of that ?


All times are GMT -5. The time now is 01:11 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.