gopro_2027
gopro_2027

Reputation: 103

Return Content Only In Socket C++

Is there a way to have a socket response only return the content of the page and not the header?

Example:

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>

and I want it to look like

<body>
  <p>
    Hello World!
  </p>
</body>

Thanks!

Upvotes: 0

Views: 262

Answers (1)

gopro_2027
gopro_2027

Reputation: 103

I ended up creating my own stuff for it

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];
    }
}

and to actually use it

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");

Upvotes: 1

Related Questions