0

I am testing my pset6 code but it is given an error of 405 method not allowed and I do not understand why? Please help me !! Thank you in advance!

//define elements to be checked
            int length = strlen(line);
            char method_checker[4];
            method_checker[4]= '\0';


            //Check if method is get
            for (int i=0; i<3;i++){

                strcpy(method_checker, &line[i]);
            }

            //continue man page http://www.tutorialspoint.com/cprogramming/c_continue_statement.htm
            if (strcmp(method_checker, "GET") != 0) {

                error(405);
                continue;
            }

 The error is:

GET /cat.jpg HTTP/1.1
HTTP/1.1 405 Method Not Allowed

1 Answer 1

2

Hmmm.....

char method_checker[4];
method_checker[4]= '\0';

You are setting '\0' one element beyond the end of method_checker[]. This is also probably leaving garbage data at method_checker[3] before you do the compare. Remember, the index starts at 0, not 1, so method_checker[] has elements 0, 1, 2 and 3 only.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .