"Go http2curl"의 두 판 사이의 차이

14번째 줄: 14번째 줄:


func req2curl(req *http.Request) string {
func req2curl(req *http.Request) string {
out, _ := http2curl.GetCurlCommand(req)
return out.String()
return out.String()
}
}
20번째 줄: 19번째 줄:
func main() {
func main() {
var req *http.Request
var req *http.Request
var curl string


req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", nil)
req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", nil)
fmt.Println(req2curl(req))
curl, _ = http2curl.GetCurlCommand(req)
fmt.Println(curl)


req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer(nil))
req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer(nil))
fmt.Println(req2curl(req))
curl, _ = http2curl.GetCurlCommand(req)
fmt.Println(curl)


str := ""
str := ""
req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer([]byte(str)))
req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer([]byte(str)))
fmt.Println(req2curl(req))
curl, _ = http2curl.GetCurlCommand(req)
fmt.Println(curl)
}
}
</syntaxhighlight>
</syntaxhighlight>
50번째 줄: 53번째 줄:
command, _ := http2curl.GetCurlCommand(req)
command, _ := http2curl.GetCurlCommand(req)
fmt.Println(command)
fmt.Println(command)
// curl -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
}
}
</syntaxhighlight>
</syntaxhighlight>

2024년 6월 17일 (월) 15:45 판

1 개요

Go http2curl
package main

import (
	"bytes"
	"fmt"
	"net/http"

	"moul.io/http2curl"
)

func req2curl(req *http.Request) string {
	return out.String()
}

func main() {
	var req *http.Request
	var curl string

	req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", nil)
	curl, _ = http2curl.GetCurlCommand(req)
	fmt.Println(curl)

	req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer(nil))
	curl, _ = http2curl.GetCurlCommand(req)
	fmt.Println(curl)

	str := ""
	req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer([]byte(str)))
	curl, _ = http2curl.GetCurlCommand(req)
	fmt.Println(curl)
}
package main

import (
	"bytes"
	"fmt"
	"net/http"

	"moul.io/http2curl"
)

func main() {
	data := bytes.NewBufferString(`{"hello":"world","answer":42}`)
	req, _ := http.NewRequest("PUT", "http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu", data)
	req.Header.Set("Content-Type", "application/json")

	command, _ := http2curl.GetCurlCommand(req)
	fmt.Println(command)
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}