Browse Source

todo

tags/v0.9.2
3136352472 5 years ago
parent
commit
7f408b4582
  1. 21
      jsruntime/go_request.go

21
jsruntime/go_request.go

@ -3,22 +3,35 @@ package jsruntime
import ( import (
"encoding/json" "encoding/json"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo" "git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo"
"github.com/parnurzeal/gorequest"
"net/http"
) )
func (jr *JsRuntime) EnableRequestFunc() { 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"] data := call["data"]
//header := call.Argument(2)
header := call["header"].(map[string]string)
//timeout := call.Argument(3) //timeout := call.Argument(3)
method := call["method"]
method := call["method"].(string)
//dataType := call["dataType"] //dataType := call["dataType"]
//responseType := call["responseType"] //responseType := call["responseType"]
//log.Println("url.String()", url) //log.Println("url.String()", url)
//log.Println("data.String()", data) //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{ res, err := hskhttpdo.HttpDo{
Url: url, Url: url,
Raw: []byte(data), Raw: []byte(data),

Loading…
Cancel
Save