zoukankan      html  css  js  c++  java
  • golang (5) http 请求分析

    http 分析包分析

    	fmt.Println("get Content-Type: ", r.Header.Get("Content-Type"))
    	var reader io.Reader = r.Body
    	b, e := ioutil.ReadAll(reader)
    	if e != nil {
    		fmt.Println("get body: ", string(b))
    	}
    	fmt.Println("get body: ", string(b))
    	err := r.ParseForm()
    	if err != nil {
    		common.HttpRspSend(w, STATUS_BAD_PARAM, "param parse is error: "+err.Error())
    		return
    	}
    
    	if len(r.Form) == 0 {
    		fmt.Println("no from ")
    		common.HttpRspSend(w, STATUS_BAD_PARAM, "no request param ")
    		return
    	}
    	if len(r.PostForm) == 0 {
    		fmt.Println("no post param")
    		common.HttpRspSend(w, STATUS_BAD_PARAM, "no request param ")
    		return
    	}
    
    	form := r.PostForm
    	fmt.Println("get cmd is ", form.Get("cmd"))
    
    	if r.Method != "POST" {
    		common.HttpRspSend(w, STATUS_BAD_PARAM, "Only POST allowed!")
    		return
    	}
    	log.Info(pretty.Sprint(form))
    
    

    https  客户端跳过http认证

    golang http请求server的https文件,出现错误
    error: certificate signed by unknown authority,
    go的Client端默认要对服务端传过来的数字证书进行校验的,如果这个证书是由不知名CA签发的,则会出先上面的错误。联想到curl的-k选项,可以跳过对服务端认证的认证。
    修改client.go的代码,让client端略过对证书的校验,如下:

    package main
    
    import (
        "crypto/tls"
        "fmt"
        "io/ioutil"
        "net/http"
    )
    
    func main() {
        tr := &http.Transport{
            TLSClientConfig:    &tls.Config{InsecureSkipVerify: true},
        }
        client := &http.Client{Transport: tr}
        resp, err := client.Get("https://localhost:8081")
    
        if err != nil {
            fmt.Println("error:", err)
            return
        }
        defer resp.Body.Close()
        body, err := ioutil.ReadAll(resp.Body)
        fmt.Println(string(body))
    }
    

    http urlencode

    欢迎评论交流
  • 相关阅读:
    mysql 查询结果中增加序号
    mycat配置文件备份
    解决Python安装模块出错 ImportError: No module named setuptools
    sed 详解【转】
    CentOS下配置SFTP操作日志
    解决redis aof文件过大的问题
    mysql主从复制搭建中几种log和pos详解
    Linux下使用命令行配置IPMI
    Zabbix笔记
    zabbix_agentd.conf配置文件详解
  • 原文地址:https://www.cnblogs.com/linengier/p/10792719.html
Copyright © 2011-2022 走看看