龙空技术网

jquery axios go的Get请求 自定义header

tinygo 158

前言:

眼前我们对“settingsajax”大致比较着重,大家都需要学习一些“settingsajax”的相关文章。那么小编也在网上搜集了一些关于“settingsajax””的相关文章,希望兄弟们能喜欢,我们一起来学习一下吧!

jquery

var settings = {  "url": ";,  "method": "GET",  "timeout": 0,  "headers": {    "token": "xxx123"  },};$.ajax(settings).done(function (response) {  console.log(response);});
axios
var axios = require('axios');var config = {  method: 'get',  url: ';,  headers: {     'token': 'xxx123'  }};axios(config).then(function (response) {  console.log(JSON.stringify(response.data));}).catch(function (error) {  console.log(error);});
go
package mainimport (  "fmt"  "net/http"  "io/ioutil")func main() {  url := ";  method := "GET"  client := &http.Client {  }  req, err := http.NewRequest(method, url, nil)  if err != nil {    fmt.Println(err)    return  }  req.Header.Add("token", "xxx123")  res, err := client.Do(req)  if err != nil {    fmt.Println(err)    return  }  defer res.Body.Close()  body, err := ioutil.ReadAll(res.Body)  if err != nil {    fmt.Println(err)    return  }  fmt.Println(string(body))}

标签: #settingsajax