curl perl Python post 发送自定义请求头
来源:互联网 发布:网络销售股票就是聊天 编辑:程序博客网 时间:2024/06/04 17:59
Star A FilePOST https://cloud.seafile.com/api2/starredfiles/Request parametersrepo_id (post)p (post)curl -v -d "repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; charset=utf-8; indent=4' http://192.168.137.1:8000/api2/starredfiles/perl 版本:##给文件加星标use LWP::UserAgent; use LWP;use Encode;use LWP::Simple;use LWP::UserAgent;use HTTP::Cookies;use HTTP::Headers;use HTTP::Response;use Encode;use URI::Escape;use URI::URL;use JSON;use Data::Dumper; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0"); my $cookie_jar = HTTP::Cookies->new( file=>'lwp_cookies.txt', autosave=>1, ignore_discard=>1); $ua->cookie_jar($cookie_jar); my $token_url= 'http://127.0.0.1:8000/api2/auth-token/'; my $res = $ua->post($token_url, { 'username'=>'015208@zjtlcb.com', 'password'=>'1234567' }); print $res->content(); print "\n"; my $r= $res->content(); my $r=encode_utf8($r); my $hash = decode_json($r); my $token =$hash->{"token"}; print "\$r is $r\n"; my $url="http://192.168.137.1:8000/api2/starredfiles/"; my $res = $ua->post($url, { 'repo_id'=>'0219ecf6-0602-4aa7-b9f2-e678255945e5', 'p'=>'/elk网址.txt' },'accept'=> "application/json; indent=4", 'content-type'=> "application/x-www-form-urlencoded", 'Authorization'=> "Token $token" ); print $res->content(); print "\n"; print $res->status_line();python 代码;# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibimport requestsdef gettoken(): data = {'username': '99999@zjtlcb.com', 'password': '1234567'} post_data = urllib.urlencode(data) # 将post消息化成可以让服务器编码的方式 cj = cookielib.CookieJar() # 获取cookiejar实例 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) # 自己设置User-Agent(可用于伪造获取,防止某些网站防ip注入) headers = {} website = "http://127.0.0.1:8000/api2/auth-token/" req = urllib2.Request(website, post_data, headers) content = opener.open(req) s = content.read() # linux下没有gbk编码,只有utf-8编码 print s print type(s) text = json.loads(s) print type(text) print text['token'] token = text['token'] return tokendef add_starred_files(): token = gettoken() token = 'Token' + ' '+ token print token data = {'repo_id': '0219ecf6-0602-4aa7-b9f2-e678255945e5', 'p': '/elk网址.txt'} post_data = urllib.urlencode(data) # 将post消息化成可以让服务器编码的方式 print post_data cj = cookielib.CookieJar() # 获取cookiejar实例 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) # 自己设置User-Agent(可用于伪造获取,防止某些网站防ip注入) headers = {"Authorization": token, "Accept": "application/json; indent=4", "content-type": "application/x-www-form-urlencoded"} website = 'http://127.0.0.1:8000/api2/starredfiles/' req = urllib2.Request(website, post_data, headers) content = opener.open(req) s = content.read() # linux下没有gbk编码,只有utf-8编码 print sadd_starred_files()
阅读全文
0 0
- curl perl Python post 发送自定义请求头
- perl 模拟curl 自定义请求头
- curl perl python post发送json数据
- curl perl python 模拟post请求
- curl perl python get请求带请求头
- perl 模拟curl post请求
- perl 自定义请求头
- perl 自定义请求头
- perl post 带上请求头
- curl命令发送Post请求
- PHP CURL发送POST请求
- 用curl 发送 post 请求
- perl post 请求加请求头
- python发送post请求
- python发送post请求
- python 发送post请求
- 使用curl和wget发送post请求
- curl发送post和get请求
- STM32学习之:定时器程序设计探讨
- C# DataGridView控件用法介绍,
- mysql插入当前时间戳
- Java发展历史
- 解决MySql Command Line Client查询结果乱码问题
- curl perl Python post 发送自定义请求头
- 编写一个程序,验证从标准输入获得的信用卡号是否校验通过, 校验通过,则输出”成功“,校验未通过则输出”失败“。
- HDU-2085核反应堆
- POJ
- jQuery min包的制作方法,压缩javascript的方法比对和方案
- AJAX中出现两次请求,OPTIONS请求和GET请求
- 优秀工程师-UIImagePickerController
- HDU-2094产生冠军
- mysql中engine=innodb和engine=myisam的区别