0

In c# I'm able to do this:

        HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/octet-stream";

        request.ContentLength = fileToSend.Length;
        request.Timeout = 2000000000;
        using (Stream requestStream = request.GetRequestStream())
        {
            // Send the file as body request.
            requestStream.Write(fileToSend, 0, fileToSend.Length);
            requestStream.Close();
        }

I'm looking for a similar object I can use in Java to take the role of HttpWebRequest, that will include a Stream.

Thanks!

edit: found this Using java.net.URLConnection to fire and handle HTTP requests but it seems much too complicated... Hopefully there is a simpler way of doing this?

Community
  • 1
  • 1
Dave
  • 1,396
  • 1
  • 15
  • 37

1 Answers1

0

I recommend you look at Apache HTTP Client (http://hc.apache.org/httpclient-3.x/features.html).

If you need just query information from some resource, then standard JDK is enough:

java.net.URL url = new java.net.URL("http://foo.bar");
URLConnection conn = url.openConnection();
//conn.getOutputStream() to place information
//conn.getInputStream() to read resource
Dewfy
  • 21,895
  • 12
  • 66
  • 114