我想通过给它的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