Emulate "file upload" with URLConnection with PHP

J

Jochen Daum

Hi,

I have to emulate a "file upload" to a Java Servlet which is done with
the class URLConnection.

The java source basically does

URLConnection conn = theurl.openConnection("https://somesite");
w = conn.getOutputStream();
w.write(...)


A thing I'm unclear of is if this connection is actually encrypted
over SSL. The other thing is if this just sends the bytes or also any
HTTP headers. If it does, how can I see, which HTTP method is used?

Thanks for any help!

Jochen
 
F

FISH

Jochen Daum said:
Hi,

I have to emulate a "file upload" to a Java Servlet which is done with
the class URLConnection.

The java source basically does

URLConnection conn = theurl.openConnection("https://somesite");
w = conn.getOutputStream();
w.write(...)

All of the answers can be found in the Javadocs...

A thing I'm unclear of is if this connection is actually encrypted
over SSL.

If it doesn't complain about a HTTPS URL then you can assume it
knows how to handle it correctly.

The other thing is if this just sends the bytes or also any
HTTP headers.

It sends both.

If it does, how can I see, which HTTP method is used?

By default it will use GET. To actually output to the URL you need
to call setDoOutput(true) before attempting to do anything which will
cause the object to connect (ie. like opening an input stream). This
will switch the method to POST and allow an output stream to be opened.
Likewise any request headers you wish to set yourself should be in
place before the object actually connects.


-FISH- ><>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top