- #请求端
- import requests #需要安装requests
- with open('test.txt', 'rb') as f:
- requests.get('http://127.0.0.1:9999', data=f)
- #服务端
- 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);
- #该片段来自于http://www.codesnippet.cn/detail/0403201511831.html
来源: http://www.codesnippet.cn/detail/0403201511831.html