内容概述

package main import ( // "bytes" "fmt" "io/ioutil" "net/http" "net/url" // "os" // "strings" ) func main() { client := &http.Client{} //向服务端发送get请求 //request, _ := http.NewRequest("GET", "

语音解读

图文解释

package main

import (
	// "bytes"
	"fmt"
	"io/IoUtil"
	"net/http"
	"net/url"
	// "os"
	// "strings"
)

func main() {
	client := &http.Client{}
	//向服务端发送get请求
	//request,_ := http.NewRequest("GET","http://192.168.1.35:9091/?publicKey=&privateKey=&info=sad&message=",nil)
	//response,_ := http.PostForm("http://192.168.1.35:9091",url.Values{"publicKey": {"-----BEGIN+PUBLIC+KEY-----%0D%0AMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZsfv1qscqYdy4vY%2BP4e3cAtmv%0D%0AppxQcRvrF1cB4drkv0haU24Y7m5qYtT52Kr539RdbKKdLAM6s20lWy7%2B5C0Dgacd%0D%0AwYWd%2F7PeCELyEipZJL07Vro7Ate8Bfjya%2BwltGK9%2BxnuIHiumUKULW4KDx21%2B1NL%0D%0AAUeJ6PeW%2BDAkmJWF6QIDAQAB%0D%0A-----END+PUBLIC+KEY-----"},"privateKey": {""},"info": {"sad"},"message": {""}})
	//接收服务端返回给客户端的信息
	// response,_ := client.Do(request)
	// if response.StatusCode == 200 {
	// 	str,_ := IoUtil.ReadAll(response.Body)
	// 	bodystr := string(str)
	// 	fmt.Println(bodystr)
	// }

	//post请求
	postValues := url.Values{}
	postValues.Add("publicKey","")
	postValues.Add("privateKey",`----nGDd4/mujoJBr5mkrw
DPwqA3N5TMNDQVGv8gMCQQCaKGJgWYgvo3/milFfImbp+m7/Y3vCptarldXrYQWO
AQjxwc71ZGBFDITYvdgJM1MTqc8xQek1FXn1vfpy2c6O
-----END RSA PRIVATE KEY-----`)
	postValues.Add("info","")
	postValues.Add("message",`DkCxcs0z6Z03uHWOHOASf2xen+7oNoSad+KG2ss0hkE79211GlgjepmMFRW4zLiF51pVYHHOBFDYYJrnokq5d0ceKYY6ONzbBYKCJMzD7guN3qMYf48Cl9g0bDVb1oMbuN2PstzORe800Q72moQaHVRPiqh7VZ6NCXnkLrtnY64=`)

	resp,err := client.PostForm("http://xxx.xxx.1.xxx:9091",postValues)
	defer resp.Body.Close()
	if err != nil {
		fmt.Println(err.Error())
	}
	if resp.StatusCode == 200 {
		body,_ := IoUtil.ReadAll(resp.Body)
		fmt.Println(string(body))
	}
}

总结

以上是编程之家为你收集整理的golang 模拟 curl post全部内容。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给好友。