Before the OSC saw an article discussing the difference between get and post, it was said that the file could not be uploaded with get. This is the example of uploading a file with Get, which is used by the client to send a GET request and the server to collect the request. The contents of the file are in the HTTP request of the body incoming past. In different languages, because I think it's easier to deal with each other. And I think the browser can make such a request, and then I will try.
Request-Side Code
Copy the Code code as follows:
Import Requests #需要安装requests
With open (' test.txt ', ' RB ') as F:
Requests.get (' http://127.0.0.1:9999 ', data=f)
Service-side code
Copy the Code code as follows:
var http = require (' http ');
var fs = require (' FS ');
var server = Http.createserver (function (req, res) {
Console.log (req);
var recdata = "";
Req.on (' Data ', function (data) {
Recdata + = data;
})
Req.on (' End ', function (data) {
Recdata + = data;
Fs.writefile (' RecData.txt ', recdata, function (err) {
Console.log (' file received ');
})
})
Res.end (' Hello ');
})
Server.listen (9999);
The above is all the code of this article, I hope you understand the Get method to upload files can be helpful.