diff --git a/jsruntime/go_request.go b/jsruntime/go_request.go index 824b0b8..37123c1 100644 --- a/jsruntime/go_request.go +++ b/jsruntime/go_request.go @@ -3,22 +3,35 @@ package jsruntime import ( "encoding/json" "git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo" + "github.com/parnurzeal/gorequest" + "net/http" ) func (jr *JsRuntime) EnableRequestFunc() { - jr.runtime.Set("GoRequest", func(call map[string]string) string { + jr.runtime.Set("GoRequest", func(call map[string]interface{}) (statusCode int, respData string) { - url := call["url"] + url := call["url"].(string) data := call["data"] - //header := call.Argument(2) + header := call["header"].(map[string]string) //timeout := call.Argument(3) - method := call["method"] + method := call["method"].(string) //dataType := call["dataType"] //responseType := call["responseType"] //log.Println("url.String()", url) //log.Println("data.String()", data) + client := &http.Client{} + + req, err := http.NewRequest("GET", url, nil) + + for e := range header { + req.Header.Add(e, header[e]) + } + resp, err := client.Do(req) + statusCode = resp.StatusCode + gorequest.New().Header. + res, err := hskhttpdo.HttpDo{ Url: url, Raw: []byte(data),