dcsimg
A simple J2me Httpconnection not working - try for yourself
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Senthil_padmanabhan
Posted On:   Tuesday, November 16, 2004 02:28 PM

			
Hi,

I am trying to acces the jpg file from the j2me client using http connection.

The code works fine for this URL http://av.warehousesports.com/sw/thumbs/BHCLBP-thumb.jpg
but the same code is not working for this URL http://www27.brinkster.com/pksenthilsub/a40.aspx

In my second case, leave about converting the byte array to the image, i am not even getting the response.

Appriciate if someone can retrieve that file in the J2me client

Thanks
-Senthil P.

Re: A simple J2me Httpconnection not working - try for yourself

Posted By:   Senthil_padmanabhan  
Posted On:   Thursday, November 18, 2004 07:41 AM

Here is the code:

m_origImage = getImage("http://av.warehousesports.com/sw/thumbs/BHCLBP-thumb.jpg");
It works

m_origImage = getImage("http://www27.brinkster.com/pksenthilsub/a40.aspx");
but not for this URL


private Image getImage(String Url) throws IOException
{
HttpConnection conn = null;
InputStream in = null;
ByteArrayOutputStream bout = null;
Image img = null;
try
{
conn = (HttpConnection)Connector.open(Url);
conn.setRequestProperty("Connection", "close");
in = conn.openInputStream();
bout = new ByteArrayOutputStream();
int b;
while ((b = in.read()) != -1)
{
bout.write(b);
}
img = Image.createImage(bout.toByteArray(), 0, bout.size());
//form.append(new ImageItem("", img, ImageItem.LAYOUT_CENTER, ""));
}
finally
{
if (conn != null)
{
conn.close();
conn = null;
}
if (in != null)
{
in.close();
in = null;
}
if (bout != null)
{
bout.close();
bout = null;
}
}
return img;
}


-------------------------------------------
I have also tried using connection and status check and all such combinations but no luck

ContentConnection connection = (ContentConnection)Connector.open(url);
conn = (HttpConnection)Connector.open(url);
int status = conn.getResponseCode();
if( status != 200 )
...
...


Thx
Senthil
About | Sitemap | Contact