• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A simple J2me Httpconnection not working - try for yourself

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first URL is a direct link to the Image file, and the second one is a ASP.NET page. I think the response of the server is completely different in the second case.

I am not sure how the .NET servers responds to the HTTP request sent by the HttpConnection.
[ November 18, 2004: Message edited by: Vijay Kiran ]
 
Senthil padmanabhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 )
...
...

Well in what way it depends on the server? Atleast i should get the stream out of the request if not the proper image right ? I am not getting even getting the stream output.

Thx
Senthil
 
Senthil padmanabhan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the aspx code:

<%@ OutputCache Duration="1" Location="none" VaryByParam="none" %>
<%@ Page Language="C#"%>

<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>


<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
string link = "http://av.warehousesports.com/sw/thumbs/BHCLBP-thumb.jpg";
System.Drawing.Image objImage ;
System.Drawing.Image objThumbnail ;
string strServerPath ;
int shtWidth ;
int shtHeight =0;


HttpWebRequest req = (HttpWebRequest)WebRequest.Create(link);
req.Method = "GET";
HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
Stream s = rep.GetResponseStream();


byte[] inBuf = new byte[1000000];
int bytesToRead = (int) inBuf.Length;
int bytesRead = 0;
while (bytesToRead > 0)
{
int n = s.Read(inBuf, bytesRead,bytesToRead);
if (n==0)
break;
bytesRead += n;
bytesToRead -= n;
}

MemoryStream memStream = new MemoryStream(inBuf);
objImage = new Bitmap(memStream);


byte[] bitmapBytes;
objImage.Save(memStream, ImageFormat.Jpeg);
bitmapBytes = memStream.ToArray();

Response.Clear();
Response.ContentType = "image/Jpeg";
//Response.AppendHeader("Content-Name","BHCLBP-thumb.jpg");
//Response.AppendHeader("Content-Version", "1.0");
//Response.AppendHeader("Content-Vendor", "skent");
//Response.AppendHeader("Content-URL", "http://av.warehousesports.com/sw/thumbs/BHCLBP-thumb.jpg");

//Response.AppendHeader("Content-type: ", "image/Jpeg");
Response.AppendHeader("Content-length", "" + (bitmapBytes.Length));
//Response.AppendHeader("Content-Disposition", "inline; filename=thumb.Jpeg");


memStream.WriteTo( Response.OutputStream );
Response.End();
objImage.Dispose();
}

</script>


---------------------------------------------------------
Here too i tried all such headers.. and even tried outputting .png but no luck
 
Vijay Kiran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the phone you are using ?
I guess there's some thing to do with UserAgent sent via http.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic