golang http get请求示例

package main

import (
	"fmt";
	"io/ioutil";
	"net/http"
)

func main() {
	client := &http.Client{}
 
    req, err := http.NewRequest("GET", "http://localhost:5863/sysapp/apaas/share/getSharePermissionRule.do?id=1", nil)
    if err != nil {
        
    }
 
    resp, err := client.Do(req)
 
    defer resp.Body.Close()
 
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        
    }
 
    fmt.Println(string(body))
}

对应后端接口(java)

    @ResponseBody
    @RequestMapping("/getSharePermissionRule")
    public ApiResponse getSharePermissionRule(String id){
        if(StringUtil.isEmpty(id)){
            return ApiResponse.failed("0","主键不能为空");
        }
        return ApiResponse.success(sharePermissionRuleService.getSharePermissionRule(StringUtil.toLong(id)));
    }

响应:

golang http get请求示例

 

上一篇:2021-10-08


下一篇:golang jwt验证