创建用户
来源:互联网 发布:ccer数据库 豆掰 编辑:程序博客网 时间:2024/05/19 21:42
Create Account:[root@node01 ~]# curl -v -X PUT -d "password=123456" -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/newaccount@gmail.com/* About to connect() to 192.168.137.1 port 8000 (#0)* Trying 192.168.137.1... connected* Connected to 192.168.137.1 (192.168.137.1) port 8000 (#0)> PUT /api2/accounts/newaccount@gmail.com/ HTTP/1.1> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2> Host: 192.168.137.1:8000> Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7> Accept: application/json; indent=4> Content-Length: 15> Content-Type: application/x-www-form-urlencoded> < HTTP/1.1 200 OK< Vary: Accept, Accept-Language, Cookie< Content-Type: application/json; indent=4< Content-Language: en< Allow: GET, POST, PUT, DELETE, HEAD, OPTIONS< Transfer-Encoding: chunked< Date: Mon, 21 Aug 2017 03:15:56 GMT< Server: localhost< * Connection #0 to host 192.168.137.1 left intact* Closing connection #0"success"[root@node01 ~]# -v/--verbose Makes the fetching more verbose/talkative. Mostly useful for debugging. A line starting with ’>’ means "header data" sent by curl, ’<’ means "header data" received by curl that is hidden in normal cases, and a line starting with ’*’ means additional info provided by curl. Note that if you only want HTTP headers in the output, -i/--include might be the option you’re looking for. If you think this option still doesn’t give you enough details, consider using --trace or --trace-ascii instead. This option overrides previous uses of --trace-ascii or --trace. Use -s/--silent to make curl quiet.确保获取更详细的,主要用于调试。以'>'开始以为着通过curl 发送的"header data",'<' 以为着收到的"header data" -X/--request <command> (HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explana- tions. Common additional HTTP requests include PUT and DELETE, but related tech- nologies like WebDAV offers PROPFIND, COPY, MOVE and more. (FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with FTP. If this option is used several times, the last one will be used.(HTTP) 指定一个自定义的请求方法来使用当和HTTP server 通讯。指定的请求会被使用来代替方法 否则使用默认的(GET)python put请求:#PUTimport urllib2request = urllib2.Request('http://example.org', data='your_put_data')request.add_header('Content-Type', 'your/contenttype')request.get_method = lambda: 'PUT'response = urllib2.urlopen(request)# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibdef 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 create_account(): token = gettoken() token = 'Token' + ' ' + token print token url = 'http://192.168.137.1:8000/api2/accounts/scan@gmail.com/' data={'password':'654321'} post_data = urllib.urlencode(data) # 将post消息化成可以让服务器编码的方式 request = urllib2.Request(url,post_data) headers = {"Authorization": token, "Accept": "application/json; indent=10", "content-type": "application/json"} #request.add_header("Authorization", token, "Accept", "application/json; indent=10", "content-type", "application/json") request.add_header('Authorization', token) request.add_header('Accept', 'application/json; indent=10') request.add_header('content-type', 'application/x-www-form-urlencoded') request.get_method = lambda: 'PUT' response = urllib2.urlopen(request) print responseif __name__ == '__main__': create_account()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/a8.py{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}<type 'str'><type 'dict'>0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7<addinfourl at 44034968 whose fp = <socket._fileobject object at 0x02A091F0>>Process finished with exit code 0
阅读全文
0 0
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- 创建用户
- Mysql 创建用户、删除用户
- Oracle创建用户、授权用户
- 管理用户安全性-创建用户
- 创建用户以及用户授权
- Oracle锁定用户、删除用户、创建用户
- SQL创建用户、创建表
- Oracle 创建用户
- 浅谈text段、data段和bss段
- mysql
- Intra Mode Coding With 4-tap Interpolation Filter
- "NetworkError: 400 Bad Request
- 排序算法
- 创建用户
- Java 全角、半角字符转化
- mysql源码脚本安装
- 算法笔记:数组和字符串
- LuoguP1820 寻找AP数
- spring 解耦实例
- 前端初学学习进程VII
- mac下安装pip
- android ValueAnimator 属性动画的用法