我想通過給它的http(s)前綴使用getaddrinfo並且它不正確地查找主機。我該如何解決這個問題。我想查找https://www.google.com但gai_strerror()
返回「沒有這樣的主機被稱爲」,它的工作好了www.google.com上的端口80c getaddrinfo沒有這樣的主機是已知的
這是我使用的的getaddrinfo部分的代碼()部分:
// The GET request I pose to download the webpage
char *send_buf="GET/\r\n";
// i tried three different urls apparently changing the value in the
// value in the variable in my code, it only works for 'www.google.com'
const char *URL="https://www.google.com";
const char *URL="http://www.google.com";
const char *URL="www.google.com";
if((status=getaddrinfo(URL, PORT, &hints, &res))!=0)
{
printf("%s\n", gai_strerror(status));
exit(1);
}
我試圖使用Winsock2的下載網頁,當我使用www.google.com,它給了我一個302感動消息,我想下載實際的網頁,而無需使用任何外部庫。
那我該如何下載網站的html? 因爲google.com爲我提供了一個302移動響應 – demogorgon
如果您已收到302響應,那麼您可以使用此鏈接[http://www.checkupdown.com/status/E302.html](http://www.checkupdown。 com/status/E302.html)來修復你的錯誤。 – Shiv
這是否有幫助.. – Shiv