0

I receive HTTP request at socket.

I want to split HTTP request at header and content.

So, I tried this source.

//p is char* type, response too
p = strtok(response, "\r\n\r\n");
while(NULL != p){
    printf("%s\n", p);
    p  = strtok(NULL, "\r\n\r\n");
}

But strtok() replaced "\r\n" by NULL too.

I want replace only "\r\n\r\n".

How should I?

1
  • 1
    Just do it manually not a big deal. Commented Mar 29, 2014 at 14:34

1 Answer 1

3

Try strstr

//p1 is char* type, response and p2 too
p1 = response;
p2 = strstr(response, "\r\n\r\n");
while(NULL != p2){
    printf("%.*s\n", p2 - p1, p1);
    p1 = p2;
    p2 = strstr(p2 + 1, "\r\n\r\n");
}
Sign up to request clarification or add additional context in comments.

3 Comments

.. and on that same site, you can read why you are using strtok wrong
I want to return Header or Content too. How can return Header or content?
to return something to the caller, copy it to the destination address (make sure it has enough space); or allocate memory and return that (make sure to free it when it's no longer needed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.