• 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 body
  • File 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.body
  • Custom 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.body
  • Basic Authentication

    require 'unirest'
    response = Unirest.get 'http://httpbin.org/get', auth:{user:'username', password:'password'}
    puts response.body
  • Request

    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 object
    • parameters (Array | Object | String) - Request Body associative array or object
    • callback (Function) - Optional; Asychronous callback method to be invoked upon result.
  • Response

    • code - HTTP Response Status Code (Example 200)
    • headers - HTTP Response Headers
    • body - 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")

    参考:http://unirest.io/ruby.html

ruby 第三方模块unirest使用的更多相关文章

  1. python 常用第三方模块

    除了内建的模块外,Python还有大量的第三方模块. 基本上,所有的第三方模块都会在https://pypi.python.org/pypi上注册,只要找到对应的模块名字,即可用pip安装. 本章介绍 ...

  2. 【Python】[模块]使用模块,安装第三方模块

    一个.py文件就称之为一个模块(Model)按目录来组织模块的方法,称为包(Package)每一个包目录下面都会有一个__init__.py的文件内置函数1.使用模块 导入模块 import sys ...

  3. 安装第三方模块方法和requests

    如何安装第三方模块 pip3         pip3 install xxxx          源码         下载,解压         进入目录 python setup.py inst ...

  4. Python:Pycharm下无法导入安装好的第三方模块?

    Pycharm下无法导入安装好的第三方模块requests? 在cmd下使用pip安装好requests模块后,可以使用import requests,但在Pycharm IDE下无法导入,出现如下错 ...

  5. python 使用pip安装第三方模块

    part 1:使用方法: 1.pip install somePackage picture 1 2.pip show somePackage 例如:pip show pip 弹出关于该模块的信息 p ...

  6. SAE上安装第三方模块

    当sae上没有自己所需要的第三方模块时,可以使用saecloud install package [package...]将所需要的模块安装到本地应用文件夹下,然后在index.wsgi下添加如何代码 ...

  7. python基础——第三方模块

    python基础——第三方模块 在Python中,安装第三方模块,是通过包管理工具pip完成的.  如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了.  如果你正在使用Window ...

  8. Python-Windows下安装BeautifulSoup和requests第三方模块

    http://blog.csdn.net/yannanxiu/article/details/50432498 首先给出官网地址: 1.Request官网 2.BeautifulSoup官网 我下载的 ...

  9. python第三方模块精选

    python不但有着强大丰富的“内置电池”,同样的,第三方模块也是非常的多.目前收集了requests.paramiko.pymsql,以后会陆续添加: 一.requests Python标准库中提供 ...

随机推荐

  1. Windows资源管理器对物理内存的描述

    对每个进程的虚拟/物理内存使用描述: 1.硬错误/秒:在最后一分钟内每秒出现的平均硬页错误数 2.提交(KB):操作系统为内存保留的虚拟内存量,任务管理器中显示为:提交大小 3.工作集(KB):进程当 ...

  2. 使用本地计划任务定时关闭azure虚拟机

    本文包含以下内容 前提条件 如何实现定时关闭虚拟机 前提条件 Controller 机器上必须安装 Azure PowerShell,并且要在 PowerShell 里登录一次 Azure, 请参见: ...

  3. 爬虫入门之urllib库(一)

    1 爬虫概述 (1)互联网爬虫 一个程序,根据Url进行爬取网页,获取有用信息 (2)核心任务 爬取网页 解析数据 难点 :爬虫和反爬虫之间的博弈 (3)爬虫语言 php 多进程和多线程支持不好 ja ...

  4. vue项目运行报错:Module bulid failed: Error: Node Sass does not yet support your current environment

    出错起因:      从GitLab clone项目 --> 用 npm install 命令下载依赖包 --> #npm run dev,报错 错误截图: 解决方法:   思路:单独 i ...

  5. idea打jar包经验总结

    关于在idea下打jar问题,在日常工作中经常用到,这里总结下流程. 1.在项目上鼠标右键 --> Open Module Settings 2.如下图,点击 '+' 3. 选择JAR --&g ...

  6. PHP:使用php,循环html中的select标签与Php数据

    select标签,我们都知道是下拉列表,这里,我们使用foreach循环,将select中的数据进行输出 例子: 1.数据表:mimi_article,表中有个字段,为1或0,表示着是或否 2.通过p ...

  7. C 中重载一词中的“重”字读ZHONG4还是CHONG2?

    in my opinion: overload: 重zhong4载override overwrite:覆盖,改写,重写.//csdn上有人问过,没有overwrite这个词 http://bbs.c ...

  8. html常见元素和理解

    html常见元素分为两类,一类是header区的元素,一类是body区的元素 header区元素: meta title style link scipt base 里面包括像meta,title,s ...

  9. 【转】Android手机分辨率基础知识(DPI,DIP计算)

    1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机是3.7英寸 A ...

  10. python logging—模块

    python logging模块 python logging提供了标准的日志接口,python logging日志分为5个等级: debug(), info(), warning(), error( ...