有没有办法让套接字响应只返回页面内容而不是标题?
示例:
HTTP/1.1 200 OK
Date: Wed, 16 Mar 2016 02:38:20 GMT
Content-Type: text/html
Connection: close
Set-Cookie: __cfduid=dad831f7d4a53291c3c112ebe9410205a1458095900; expires=Thu, 16-Mar-17 02:38:20 GMT; path=/; domain=.(my personal site);
HttpOnly
X-Powered-By: PHP/5.5.32
Vary: Accept-Encoding
Server: cloudflare-nginx
CF-RAY: 2844d412d5621159-DFW
<body>
<p>
Hello World!
</p>
</body>
我希望它看起来像
<body>
<p>
Hello World!
</p>
</body>
谢谢!
答案 0 :(得分:1)
我最终为它创建了自己的东西
int getIndexOf(char *string, char *find, int startindex = 0, bool addonlength = false) {
for (int i = startindex; i < strlen(string); i++) {
for (int j = 0; j < strlen(find); j++) {
if (string[i+j] == find[j]) {
if (j == strlen(find)-1) {
if (addonlength)
i+=strlen(find);
return i;
}
} else {
j = strlen(find);
}
}
}
return -1;
}
void substring(char string[], int x, int y) {
int len = strlen(string);
//underneath x
for (int i = 0; i < x; i++) {
if (i < len)
string[i] = 0;
}
//above y
for (int i = y; i < strlen(string); i++) {
if (i < len)
string[i] = 0;
}
//moving the rest down
for (int i = x; i < y; i++) {
if (i < len)
string[i-x] = string[i];
}
}
并实际使用它
char networkSearchString[] = "\r\n\r\n";
for (int i = 0; i < 3; i++)
ConsoleWrite("\n");
ConsoleWrite("Printing...\n");
char *text = SocketRequest("google.com","search?q=hey");
int in = getIndexOf(text,networkSearchString,0,true);
substring(text,in,strlen(text));
ConsoleWrite(text);
ConsoleWrite("\nDone");