gpt4 book ai didi

c - C 中的 GET HTTP 请求(消息体)

转载 作者:可可西里 更新时间:2023-11-01 16:55:01 25 4
gpt4 key购买 nike

<分区>

我在以下代码中使用 C 发出 GET 请求:

   char buffer[1024] =
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Accept-Language: en-US,en;q=0.5\r\n"
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
"Connection: keep-alive\r\n"
"Cache-Control: max-age=0\r\n\r\n";

size_t buffer_len = sizeof(buffer) - 1;

/* Send message to the server */
n = write(sockfd, buffer, buffer_len);

/* Now read server response */
bzero(buffer, strlen(buffer));
n = read(sockfd, buffer, buffer_len);

/* Display result */
printf("%s\n",buffer);
return 0;

正确回应:

HTTP/1.1 200 OK
Date: Mon, 19 Sep 2016 17:20:48 GMT
Server: Apache
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 6695
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8


除了最后一行应该是消息正文,而不是 html 内容它只出现一个符号�,有谁知道问题出在哪里?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com