Question

I am currently working on a simple java program that tests ping, upload speed, and download speed. It is for a class project, and therefore rather than using java's httpURLConnection package, I'm doing it manually using Java Sockets. I found it quite easy to find the format of a GET request, put cannot find the format of a PUT. Here, for example, is how my GET request looks:

//Create GET request
outToServer.writeBytes("GET / HTTP/1.1\r\n
                       + "Host: " + server + "\r\n"
                       + "Connection: close\r\n\r\n");

where outToServer is a DataOutputStream using the outputStream of a Socket. I am looking for a similar way to perform a PUT to upload a file to a server and measure the time. Thank you very much for any help!

Was it helpful?

Solution

In short, format is the same, it has "PUT" instead of "GET" and it is usually used to "add" or "update" entities in the server, so after the header you would get an empty line (\r\n\r\n) and then a body, whose content type would correspond to the header "content-type" (like, say, text/html or application/json) An example of what a PUT request would look like:

PUT /boo/foo.txt HTTP/1.1
Host: www.foo.com
Content-Type: plain/text

This is a testing content for the text file foo.txt

Now, the server must support the method PUT (it is not required for a server to support such method)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top