Code Monkey home page Code Monkey logo

requests's Introduction

request

Golang HTTP Requests for Humans™ ✨🍰✨

Usage

  • 基本用法

requests.Get("https://golang.org)
requests.Post("https://golang.org, "application/json", `{"a": "b"}`)
  • 高级用法
package main

import (
    "log"

    "github.com/luopengift/requests"
)

func main() {
    sess := requests.New()                                           // 创建session
    sess.SetHeader("aaa", "bbb")                                     // 全局配置, 会追加到使用这个sess的所有请求中
    req, err := requests.NewRequest("GET", "http://httpbin.org", nil) // 创建一个GET请求
    if err != nil {
        log.Fatal(err)
        return
    }
    req.SetHeader("foo", "bar") // req的参数设置会覆盖sess中的参数
    resp, err := sess.DoRequest(req) //发送创建的请求
    if err != nil {
        log.Fatal(err)
        return
    }
    _, err = resp.Text() //解析响应
    if err != nil {
        log.Fatal(err)
        return
    }
}

requests's People

Contributors

luopengift avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.