Re: Using POST to send bitmap image with Java



Kenneth P. Turvey wrote:
On Fri, 30 May 2008 20:53:12 +0000, Dave Miller wrote:

Dexter wrote:
In one of my Graphing programs written in Java, I am trying to send a
graphics image (.bmp) to HttpModule on the same server that hosts the
graphing applet.

I found some code on internet that helped me post text data to the
module.

Can someone suggest how I may post the graphics image binary data using
POST method

URL url = new URL("http://www.your-server.com";); HttpURLConnection
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
DataOutputStream out =
new DataOutputStream(connection.getOutputStream()); // use one of write
methods of out
out.flush();
out.close();

I'm actually in the process of doing this right now. I'm going to be posting the image to a URL that is a PHP script. When I was looking at this I thought that this really made more sense to use a PUT method to post the image, but the guy working on the PHP side insisted on using a POST method.

Is there a reason that POST would be selected over PUT for this application? Are there reasons to go with PUT here?

Thanks.

If you are sending other data with the request(i.e. a caption for the picture), POST is the designed protocol. If you are just sending a file to be saved to the server use PUT or POST. In other words POST is designed to put but PUT isn't meant to post. It's a distinction without a difference from your side of the code - if the PHP guy want's POST ...

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

--
Dave Miller
Java Web Hosting at:
http://www.cheap-jsp-hosting.com/
.



Relevant Pages

  • Re: Using POST to send bitmap image with Java
    ... graphics image to HttpModule on the same server that hosts the ... Can someone suggest how I may post the graphics image binary data using ... POST method ... high-level framework. ...
    (comp.lang.java.programmer)
  • Re: Using POST to send bitmap image with Java
    ... Can someone suggest how I may post the graphics image binary data using ... POST method ... Is there a reason that POST would be selected over PUT for this ... As we enjoy great advantages from the inventions of others, ...
    (comp.lang.java.programmer)
  • Re: Using POST to send bitmap image with Java
    ... Can someone suggest how I may post the graphics image binary data ... using POST method ... URL url = new URL; ...
    (comp.lang.java.programmer)
  • Re: How may I implement this functionality using ASP.Net ?
    ... I am currently contemplating moving from PHP to ASP.Net at the server side. ... Basically it means I can call this url with some arguments from my C++ code (POST method), which then invokes the appropriate function on the server side. ... I mean if I have a 'page' called 'functions.aspx', could I pass it parameters via POST and invoke methods in say a "code-behind" C# library? ...
    (microsoft.public.dotnet.framework.aspnet)
  • J2ME HTTP Post Method Problem
    ... I built a midlet that sends an information by POST method in HTTP ... but the data doesn't arrive to the server. ... Here is Simple PHP file which is on the server: ...
    (comp.lang.java.programmer)