Python uploads files using get method _python

Source: Internet
Author: User
Tags http request

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.

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.