mirror of
https://github.com/taigrr/wasm-experiments
synced 2025-01-18 04:03:21 -08:00
Add context test to fetch
This commit is contained in:
parent
b31231ab0a
commit
d8c7440fdb
@ -15,15 +15,25 @@ func main() {
|
|||||||
c := http.Client{
|
c := http.Client{
|
||||||
Transport: &fetch.Transport{},
|
Transport: &fetch.Transport{},
|
||||||
}
|
}
|
||||||
resp, err := c.Post(
|
req, err := http.NewRequest(
|
||||||
|
"POST",
|
||||||
"https://httpbin.org/anything",
|
"https://httpbin.org/anything",
|
||||||
"application/json",
|
|
||||||
strings.NewReader(`{"test":"test"}`),
|
strings.NewReader(`{"test":"test"}`),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*200)
|
||||||
|
defer cancel()
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
*/
|
||||||
|
resp, err := c.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user