Git Product home page Git Product logo

win's Introduction

Win

๐Ÿช Buy me a cookie

Go Report Card

What is this?

This Go module wraps WinHTTP and WinINet functions and includes HTTP clients that use those functions to make HTTP requests. Hopefully, this makes it easier to make HTTP requests in Go on Windows. WinHTTP (and theoretically WinINet) can even handle NTLM authentication automatically for you.

Microsoft recommends WinINet over WinHTTP unless you're writing a Windows service.

Note: This is probably beta quality at best.

How to install

Open a terminal and run the following:

$ go get --ldflags="-s -w" --trimpath -u gitlab.com/mjwhitta/win

Usage

Minimal example:

package main

import (
    "fmt"
    "io/ioutil"

    // "gitlab.com/mjwhitta/win/winhttp/http"
    "gitlab.com/mjwhitta/win/wininet/http"
)

func main() {
    var b []byte
    var dst = "http://127.0.0.1:8080/asdf"
    var e error
    var headers = map[string]string{
        "User-Agent": "testing, testing, 1, 2, 3...",
    }
    var req *http.Request
    var res *http.Response

    http.DefaultClient.TLSClientConfig.InsecureSkipVerify = true

    if _, e = http.Get(dst); e != nil {
        panic(e)
    }

    req = http.NewRequest(http.MethodPost, dst, []byte("test"))
    req.AddCookie(&http.Cookie{Name: "chocolatechip", Value: "tasty"})
    req.AddCookie(&http.Cookie{Name: "oatmealraisin", Value: "gross"})
    req.AddCookie(&http.Cookie{Name: "snickerdoodle", Value: "yummy"})
    req.Headers = headers

    if res, e = http.DefaultClient.Do(req); e != nil {
        panic(e)
    }

    if res.Body != nil {
        if b, e = ioutil.ReadAll(res.Body); e != nil {
            panic(e)
        }
    }

    fmt.Println(res.Status)
    for k, vs := range res.Header {
        for _, v := range vs {
            fmt.Printf("%s: %s\n", k, v)
        }
    }
    if len(b) > 0 {
        fmt.Println(string(b))
    }

    if len(res.Cookies()) > 0 {
        fmt.Println()
        fmt.Println("# COOKIEJAR")
    }

    for _, cookie := range res.Cookies() {
        fmt.Printf("%s = %s\n", cookie.Name, cookie.Value)
    }
}

Links

TODO

  • Mirror net/http as close as possible
    • CookieJar for the Client
    • etc...
  • WinINet
    • FTP client

win's People

Contributors

mjwhitta 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.