Code Monkey home page Code Monkey logo

direwolf's Introduction

Direwolf HTTP Client: Save your time

Build Status codecov GitHub release (latest by date) language GitHub

Package direwolf is a convenient and easy to use http client written in Golang.

If you want find more info, please go here: Direwolf HTTP Client: Save your time,内有中文文档。

direwolf

Feature Support

  • Clean and Convenient API
  • Simple to Set Headers, Cookies, Parameters, Post Forms
  • Sessions Control
  • Keep-Alive & Connection Pooling
  • HTTP(S) Proxy Support
  • Redirect Control
  • Timeout Control
  • Support extract result from response body with css selector, regexp, json
  • Content Decoding
  • More to come...

Installation

go get github.com/wnanbei/direwolf

Take a glance

You can easily send a request like this:

import (
    "fmt"

    dw "github.com/wnanbei/direwolf"
)

func main() {
    resp, err := dw.Get("https://www.google.com")
    if err != nil {
        return
    }
    fmt.Println(resp.Text())
}

Besides, direwolf provide a convenient way to add parameters to request. Such as Headers, Cookies, Params, etc.

import (
    "fmt"

    dw "github.com/wnanbei/direwolf"
)

func main() {
    headers := dw.NewHeaders(
        "User-Agent", "direwolf",
    )
    params := dw.NewParams(
        "name", "wnanbei",
        "age", "18",
    )
    cookies := dw.NewCookies(
        "sign", "kzhxciuvyqwekhiuxcyvnkjdhiue",
    )
    resp, err := dw.Get("https://httpbin.org/get", headers, params, cookies)
    if err != nil {
        return
    }
    fmt.Println(resp.Text())
}

Output:

{
    "args": {
        "age": "18",
        "name": "wnanbei"
    },
    "headers": {
        "Accept-Encoding": "gzip",
        "Cookie": "sign=kzhxciuvyqwekhiuxcyvnkjdhiue",
        "Host": "httpbin.org",
        "User-Agent": "direwolf"
    },
    "origin": "1.1.1.1, 1.1.1.1",
    "url": "https://httpbin.org/get?age=18&name=wnanbei"
}

Contribute

Direwolf is a personal project now, but all contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

If you find a bug in direwolf or have some good ideas:

  • Go to GitHub “issues” tab and open a fresh issue to start a discussion around a feature idea or a bug.
  • Send a pull request and bug the maintainer until it gets merged and published.
  • Write a test which shows that the bug was fixed or that the feature works as expected.

If you need to discuss about direwolf with me, you can send me a e-mail.

direwolf's People

Contributors

wnanbei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

direwolf's Issues

read Response.Body failed unexpected EOF

package main

import (
	"fmt"
	dw "github.com/wnanbei/direwolf"
)

func main() {
	url := "https://blog.csdn.net/u013451157/article/details/78719374"
	headers := dw.NewHeaders(
		"User-Agent", "direwolf",
	)
	resp, err := dw.Get(url, headers)
	if  nil !=  err{
		fmt.Println(err)
		return
	}
	//fmt.Println(resp.Text())

	fmt.Println(string(resp.Content()))
}

Post 表单

Post 表单只能设置[string]string
实际情况下有[string]int的情形

Params not work as expected

params := df.NewParams("aa", "bb")

resp, err := df.Get("https://httpbin.org/get?ss=sd",params)

if err != nil {
	return
}

fmt.Println(resp.Text())

return

{
  "args": {
    "ss": "sd?aa=bb"
  }, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Host": "httpbin.org", 
    "User-Agent": "direwolf - winter is coming"
  }, 
  "origin": "123.103.48.253, 123.103.48.253", 
  "url": "https://httpbin.org/get?ss=sd%3Faa=bb"
}

Seems like Params's bindRequest method not taking into account the fact that there are parameters on the url

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.