ruby 第三方模块unirest使用
Creating Requests
require 'unirest'
response = Unirest.post 'http://httpbin.org/post',
headers:{ Accept:'application/json' },
parameters:{ age: 23, foo:'bar' } puts response.code # Status code
puts response.headers # Response headers
puts response.body # Parsed body
puts response.raw_body # Unparsed bodyFile Uploads
require 'unirest'
Unirest.timeout(30)
response = Unirest.post 'http://httpbin.org/post',
headers:{ Accept:'application/json' },
parameters:{ age:23, file:File.new(__dir__+'/test.text', 'rb') }
puts response.bodyCustom Entity Body
require 'unirest'
response = Unirest.post 'http://httpbin.org/post',
headers:{ Accept:'application/json' },
parameters:{ age:'value', foo:'bar' }.to_json # Converting the Hash to a JSON string
puts response.bodyBasic Authentication
require 'unirest'
response = Unirest.get 'http://httpbin.org/get', auth:{user:'username', password:'password'}
puts response.bodyRequest
Unirest.get(url, headers: {}, parameters: nil, auth:nil, &callback)
Unirest.post(url, headers: {}, parameters: nil, auth:nil, &callback)
Unirest.delete(url, headers: {}, parameters: nil, auth:nil, &callback)
Unirest.put(url, headers: {}, parameters: nil, auth:nil, &callback)
Unirest.patch(url, headers: {}, parameters: nil, auth:nil, &callback)url(String) - Endpoint, address, or uri to be acted upon and requested information from.headers(Object) - Request Headers as associative array or objectparameters(Array|Object|String) - Request Body associative array or objectcallback(Function) - Optional; Asychronous callback method to be invoked upon result.
Response
code- HTTP Response Status Code (Example200)headers- HTTP Response Headersbody- Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.raw_body- Un-parsed response body
Advanced Configuration
Timeout
Unirest.timeout(5) # 5s timeout
Default Request Headers
Unirest.default_header('Header1','Value1')
Unirest.default_header('Header2','Value2')
Unirest.clear_default_headers()User-Agent
Unirest.user_agent("custom_user_agent")
ruby 第三方模块unirest使用的更多相关文章
- python 常用第三方模块
除了内建的模块外,Python还有大量的第三方模块. 基本上,所有的第三方模块都会在https://pypi.python.org/pypi上注册,只要找到对应的模块名字,即可用pip安装. 本章介绍 ...
- 【Python】[模块]使用模块,安装第三方模块
一个.py文件就称之为一个模块(Model)按目录来组织模块的方法,称为包(Package)每一个包目录下面都会有一个__init__.py的文件内置函数1.使用模块 导入模块 import sys ...
- 安装第三方模块方法和requests
如何安装第三方模块 pip3 pip3 install xxxx 源码 下载,解压 进入目录 python setup.py inst ...
- Python:Pycharm下无法导入安装好的第三方模块?
Pycharm下无法导入安装好的第三方模块requests? 在cmd下使用pip安装好requests模块后,可以使用import requests,但在Pycharm IDE下无法导入,出现如下错 ...
- python 使用pip安装第三方模块
part 1:使用方法: 1.pip install somePackage picture 1 2.pip show somePackage 例如:pip show pip 弹出关于该模块的信息 p ...
- SAE上安装第三方模块
当sae上没有自己所需要的第三方模块时,可以使用saecloud install package [package...]将所需要的模块安装到本地应用文件夹下,然后在index.wsgi下添加如何代码 ...
- python基础——第三方模块
python基础——第三方模块 在Python中,安装第三方模块,是通过包管理工具pip完成的. 如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了. 如果你正在使用Window ...
- Python-Windows下安装BeautifulSoup和requests第三方模块
http://blog.csdn.net/yannanxiu/article/details/50432498 首先给出官网地址: 1.Request官网 2.BeautifulSoup官网 我下载的 ...
- python第三方模块精选
python不但有着强大丰富的“内置电池”,同样的,第三方模块也是非常的多.目前收集了requests.paramiko.pymsql,以后会陆续添加: 一.requests Python标准库中提供 ...
随机推荐
- django-1-应用开发基本套路
Django 开发基本流程 创建项目 创建应用 修改配置文件 设计数据模型 后台管理注册 编写业务视图 编写模板文件 设置URL 访问测试/调试 部署上线 创建项目 django-admin star ...
- 开发者为何对Service Fabric爱不释手?值得关注!
有了它,人人都可开发高可用高伸缩应用.今天小编就为大家介绍一款开发者的“利器”——Service Fabric . 在介绍它之前,先来了解一下它的背景. Service Fabric 是一款应用程序平 ...
- 织梦Dedecms主要文件夹目录及模板文件说明
虽然织梦DedeCMS因为安全问题被人所诟病,但瑕不掩瑜,无论从用户群数量还是时间等各方面,织梦DedeCMS都是国内排名前几的CMS建站程序.如果你想学习CMS的二次开发,织梦DedeCMS是必须需 ...
- 用 dbgrid 或 dbgrideh 如何让所显示数据自动滚动
procedure TForm1.Timer1Timer(Sender: TObject);varm:tmessage;begin m.Msg:=WM_VSCROLL; m.WParamLo:=SB_ ...
- 浏览器下出现net::ERR_BLOCKED_BY_CLIENT的解决办法
转发网址:https://www.cnblogs.com/wenzheshen/p/7724065.html 当我们在做开发时,调试页面图片会出现部分图片无法正常显示,并且确认图片的地址正确: 按F1 ...
- 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】
F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...
- ssh公钥
想要将本地电脑的文件传到github上,必须要通过建立本地电脑与github帐号的ssh公钥才行. 方式: 用命令ssh-keygen产生ssh公钥(之后一直按回车就好),然后cd到~/.ssh目录, ...
- 【遥感专题系列】微波遥感(二、合成孔径雷达SAR基础)
目前使用最广的成像雷达系统就是合成孔径雷达(Synthetic Aperture Radar:SAR),SAR几乎成为了雷达的代名词.本文从应用角度介绍SAR系统的基本知识. 本文主要包括: SAR基 ...
- 【luogu P1455 搭配购买】 题解
题目链接:https://www.luogu.org/problemnew/show/P1455 一句话题目做法:并查集合并+01背包 启示:要每次再find一遍.路径压缩会快.因为合并的时候如果是1 ...
- js箭头函数
ES6标准新增了一种新的函数:Arrow Function(箭头函数). 为什么叫Arrow Function?因为它的定义用的就是一个箭头 x =>x*x 相当于: function(x) { ...