Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.99 KB

README.org

File metadata and controls

71 lines (52 loc) · 1.99 KB

About

https://godoc.org/github.com/kumakichi/goamf?status.png

This repository is based on amf.go written by paulhodge, and I add and modify codes according to PyAMF.

Currently, support AMF3 only.

Normally, you need only NewRequest, and maybe ParseRespBody. For more detail infomation, read the doc.

Example

package main

import (
        "fmt"
        "io"
        "io/ioutil"
        "log"
        "net/http"

        "github.com/kumakichi/goamf"
)

const (
        URL = "http://aqi.zjemc.org.cn/aqi/messagebroker/amf"
)

func main() {
        //You can send mutiple requests per time, like this:
        //
        //reader, header, err := amf.NewRequest([]interface{}{
        //      []interface{}{"getAreaDayReprotData", "GisCommonDataUtil"},
        //      []interface{}{"getAreaRealTimeReportData", "GisCommonDataUtil"},
        //})

        //Single request
        reader, header, err := amf.NewRequest("getAreaDayReprotData", "GisCommonDataUtil")
        checkError(err)

        b := requestWithHeader(reader, header)

        body, err := amf.ParseRespBody(b)
        checkError(err)
        fmt.Printf("Body size: %d,%v\n", len(body), body)
}

func checkError(err error) {
        if err != nil {
                log.Fatal(err)
        }
}

func requestWithHeader(reader io.Reader, header http.Header) []byte {
        client := &http.Client{}
        req, err := http.NewRequest("POST", URL, reader)
        checkError(err)

        req.Header = header
        resp, err := client.Do(req)
        checkError(err)

        defer resp.Body.Close()

        b, err := ioutil.ReadAll(resp.Body)
        checkError(err)

        return b
}