Before the OSC saw an article to discuss the difference between get and post, some people said that can not use get to upload files. This is an example of using get upload file, the client is used to send a GET request, the server is used to collect requests. The contents of the file are incoming over the body of the HTTP request. I use 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 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 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);
That's all the code in this article, and I want to be able to help you understand the Get method upload file.