char url[]= "GET " PATH "\r\n"
"Host: " HOST "\r\n"
"User-Agent: Mozilla/5.0\r\n"
"\r\n";
write(sfd, url, strlen(url)); // write(fd, char[]*, len);
bzero(buffer, BUFFER_SIZE);
while(read(sfd, buffer, 1024 - 1) != 0){
printf("%s", BUFFER_SIZE);
bzero(buffer, 1024);
}
我正在使用Socket编写HTTP客户端。这里的问题是read()函数只返回HTTP响应体。但我希望它也能获取http响应头。我不知道我在这里做错了什么。
答案 0 :(得分:3)
问题是您没有在data = structure(list(Sex = structure(c(2L, 1L, 2L, 2L, 1L), .Label = c("F",
"M"), class = "factor"), A = c(1L, 2L, 39L, 24L, 11L), B = c(20L,
10L, 32L, 43L, 3L), C = c(45L, 32L, 2L, 2L, 4L), D = c(42L, 23L,
23L, 44L, 4L), E = c(12L, 43L, 43L, 12L, 11L)), .Names = c("Sex",
"A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA,
-5L))
请求中指定HTTP版本,因此服务器会认为您是1.0之前的客户端,并且不会向您发送任何标头。
请改为:
GET
或者:
char url[]= "GET " PATH " HTTP/1.0\r\n" ...
然后服务器会给你标题。