Python uploads a file using the Get method

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.