got
got copied to clipboard
Got is stuck without response
What would you like to discuss?
import got from 'got';
var options = {
'method': 'GET',
'url': 'https://www.yodobashi.com/product/100000086601417151/',
'headers': {
'Host': 'www.yodobashi.com',
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Accept-Language': 'en-US,en;q=0.9',
}
};
got(options).then(response=>{
console.log(response.body)
});
it is stuck without any response.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://www.yodobashi.com/product/100000086601417151/"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Host", "www.yodobashi.com")
req.Header.Add("sec-ch-ua", "\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\"")
req.Header.Add("sec-ch-ua-mobile", "?0")
req.Header.Add("sec-ch-ua-platform", "\"Windows\"")
req.Header.Add("Upgrade-Insecure-Requests", "1")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36")
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
req.Header.Add("Sec-Fetch-Site", "none")
req.Header.Add("Sec-Fetch-Mode", "navigate")
req.Header.Add("Sec-Fetch-User", "?1")
req.Header.Add("Sec-Fetch-Dest", "document")
req.Header.Add("Accept-Language", "en-US,en;q=0.9")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
The golang returns the response immediately for the same request. What happens here? What should I do to make it work
Checklist
- [ ] I have read the documentation.
...
The golang returns the response immediately for the same request. What happens here? What should I do to make it work
Checklist
- [ ] I have read the documentation. @future-mine Were you able to determine why this was not working?
yeah, the listener documentation for get/post vs stream isn't useful at all. I haven't been able to get much out of .on('response'... on got.post at all. .then is not valid for got promises. this seems to get a statuscode
let something= await got("https://somewebsite.com");
something.statusCode;
see https://github.com/sindresorhus/got/blob/main/documentation/3-streams.md#response-2