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

(새 문서: ==개요== ;Go http2curl <syntaxhighlight lang='go' run> package main import ( "bytes" "fmt" "net/http" "github.com/moul/http2curl" ) func req2curl(req *http.Request) string {...)
 
 
(같은 사용자의 중간 판 6개는 보이지 않습니다)
10번째 줄: 10번째 줄:
"net/http"
"net/http"


"github.com/moul/http2curl"
"moul.io/http2curl"
)
)


32번째 줄: 32번째 줄:
}
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='go' run>
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)
}
</syntaxhighlight>


==같이 보기==
==같이 보기==
39번째 줄: 58번째 줄:
==참고==
==참고==
* https://github.com/moul/http2curl
* https://github.com/moul/http2curl
* https://pkg.go.dev/moul.io/http2curl/v2


[[분류: Go]]
[[분류: Go]]

2024년 6월 17일 (월) 15:48 기준 최신판

1 개요[ | ]

Go http2curl
package main

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

	"moul.io/http2curl"
)

func req2curl(req *http.Request) string {
	out, _ := http2curl.GetCurlCommand(req)
	return out.String()
}

func main() {
	var req *http.Request

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

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

	str := ""
	req, _ = http.NewRequest(http.MethodGet, "https://github.com/manifest.json", bytes.NewBuffer([]byte(str)))
	fmt.Println(req2curl(req))
}
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 }}