+ Reply to Thread
Results 1 to 8 of 8

Thread: CGI script problem written in C

  1. #1
    Full Member whiteknight is on a distinguished road
    Join Date
    Jan 2004
    Location
    Philadelphia
    Posts
    42

    CGI script problem written in C

    yeah, i know this is the perl forum, but it is as close to a C forum as I could get here, plus, i am doing CGI work, so it almost fits...

    anyway, I have a script that i am writting that simply wont display on my browser. I POST data to it from a very simple form, and i always get ERROR 500 "premature end of script headers"

    I assume I am reading the post data wrong, because when i dont read any data, i dont get any error.

    IIRC, the code for reading this post data would be
    Code:
    char content_data[512];
    scanf("%s", content_data);
    and then i can manipulate the string data from there.

    of course, this might not be the problem at all.

    I am printing functional MIME headers...
    thats right, I am the webmaster.

  2. #2
    Newbie ggx is on a distinguished road
    Join Date
    Jan 2004
    Posts
    3
    Sorry pal, I have no idea. But, you surely printed a blank line after the HTTP header, didn't you?

  3. #3
    Full Member whiteknight is on a distinguished road
    Join Date
    Jan 2004
    Location
    Philadelphia
    Posts
    42
    yeah, i figured out my problem. i did print the correct MIME header, but i didnt get the input data correctly. getting the data is a lengthy and complicated process, so if anybody is interested in how to do it, let me know.

  4. #4
    Web Junky Matt is on a distinguished road
    Join Date
    Dec 2003
    Posts
    71
    Originally posted by whiteknight
    yeah, i figured out my problem. i did print the correct MIME header, but i didnt get the input data correctly. getting the data is a lengthy and complicated process, so if anybody is interested in how to do it, let me know.
    Feel free to post your solution for further references.
    WebmasterLingo.com Team
    Forum Rules

    "Anyone who has never made a mistake has never tried anything new" - Albert Einstein

  5. #5
    Full Member whiteknight is on a distinguished road
    Join Date
    Jan 2004
    Location
    Philadelphia
    Posts
    42
    oh, good call matt. I'm sure it might be usefull eventually, if only on accident...

    Code:
    #include <stdlib>
    #include <stdio>
    
    ...
    
    char *query_string;
    int content_length;
    
    content_length = atoi(getenv("CONTENT_LENGTH");
    query_string = (char *) malloc(content_length);
    fread(query_string, content_length, 1, stdin);
    query_string[content_length] = "\0";
    
    ...
    that little bit of code will take all your post data from a form, and set it all up in a char string. your string of course, will be in the form "field1=value1&field2=value2&.....etc"

    which you would then have to parse and separate in a different function later.

    in general, I've learned that it is much better to use perl.
    thats right, I am the webmaster.

  6. #6
    Newbie ggx is on a distinguished road
    Join Date
    Jan 2004
    Posts
    3
    Thanks for the info whiteknight! I always wanted to play around C, and I got something good to do now

    And yes, Perl is definately the best language to use for CGI programs

  7. #7
    Full Member Matrix28 is on a distinguished road
    Join Date
    Feb 2004
    Posts
    34
    Are you printing out headers? I didn't know you could use C for CGI!

  8. #8
    Full Member whiteknight is on a distinguished road
    Join Date
    Jan 2004
    Location
    Philadelphia
    Posts
    42
    you can use any language really. I did a little ditty program in bash script, and my buddy did one in basic.

    you have to print out the headers every time though, so the server knows whats going on. I just omitted the code for it

    on my site, I actually have 2 scripts now written in C. granted i could have done them both in perl much faster and easier, but i love the challenge.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts