• 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

最新文章

  1. 配合crond服务实现自定义周期备份MySQL数据库(使用innobackupex进行备份)
  2. ant学习
  3. constraint使用方法总结
  4. 网络编程Socket UDP
  5. JMX学习笔记(三)-MXBean
  6. JAVA如何解析多层json数据
  7. 网狐6603 cocos2dx 棋牌、捕鱼、休闲类游戏《李逵捕鱼》手机端完整源码分析及分享
  8. sql语句之字符串匹配like
  9. Android SQLite与ListView的简单使用
  10. 社工数据搜索引擎搭建 - Build Social Engineer Evildata Search Engine
  11. "C#":MySql批量数量导入
  12. Linux中的update和upgrade的区别
  13. ORA-01034 报错
  14. MFC笔记5
  15. AES-GCM算法
  16. Ubuntu 16.04 root环境变量不生效问题解决方案
  17. UVA-714-二分+贪心
  18. noip第13课作业
  19. Nginx+Keepalived实现站点高可用[z]
  20. struts2为什么action要继承actionSupport类

热门文章

  1. 【NLP_Stanford课堂】最小编辑距离
  2. JS检查输入项是否为手机号码或者固话号码的正则表达式
  3. 【Spring实战】—— 2 构造注入
  4. 数据结构与算法分析java——树2(二叉树类型)
  5. IOS 通讯录 (访问,添加,修改)
  6. 【翻译】苹果官网的命名规范之 Naming Properties and Data Types
  7. Ubuntu 16.04 源码方式安装 JDK
  8. 【洛谷P1118】数字三角形
  9. Zookeeper watch参照表
  10. 简单实现CombineFileInputFormat