Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307730
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:26:24+00:00 2026-05-17T21:26:24+00:00

I built a program that parses the header and I would like to read

  • 0

I built a program that parses the header and I would like to read the message body in case I receive a POST.

For headers, I have been able to look for to determine when the header ends. I am having more issues for the message body. Am I supposed to look at “Content-Length” field to know when to stop reading input? In my current code (below), it will not stop until I hit the red cross (stop loading page) in Firefox.

Here is the code:

size_t n;
unsigned char newChar;

int index = 0;
int capacity = 50;
char *option = (char *) malloc(sizeof(char) * capacity); 

while ( ( n = read( req->socket, &newChar, sizeof(newChar) ) ) > 0 ) {
  if (newChar == '\0' || newChar == '\n') break; // This is not working

  if (index == capacity) {
    capacity *= 2;
    option = (char *) realloc(option, sizeof(char) * capacity);
    assert(option != NULL);
  }
  option[index++] = newChar;
  fprintf(stderr, "%c", newChar);
}

if (index == capacity) {
  capacity *= 2;
  option = (char *) realloc(option, sizeof(char) * capacity);
  assert(option != NULL);
}
option[index] = '\0';

The correct input gets printed, but I wonder why it won’t stop until the stop loading button get pressed. I’d like to know if there is any other solution or if I please need to use the “Content-Length” field in the header.

Thank you very much,

Jary

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:26:24+00:00Added an answer on May 17, 2026 at 9:26 pm

    There are a few things to consider. You’ll want to consider how you want to handle all of these cases perhaps?

    • For HTTP protocol 1.0 the connection closing was used to signal the end of data.

    • This was improved in HTTP 1.1 which supports persistant connections. For HTTP 1.1 typically you set or read the Content-Length header to know how much data to expect.

    • Finally with HTTP 1.1 there is also the possibility of “Chunked” mode, you get the size as they come and you know you’ve reached the end when a chunk Size == 0 is found.

    Also do you know about libcurl? It will certainly help you having to re-implement the wheel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently built a program that parses a remote file from \some_server\c$\directory\file.xls and it
I built a little program that calculates the average of 15 numbers or less.
I am finishing off a C# ASP.NET program that allows the user to build
I've just built a VS C++ 6.0 program using VS 2008. When I attempt
I built a Winform app several months ago that schedules appointments for repair techs.
My goal is to have all object files built in a .objs directory instead
My application receives strings that represent objects. I have to parse the strings to
I'm making a program which the user build directories (not in windows, in my
Generally when I use ClickOnce when I build a VB.NET program but it has
Which built in (if any) tool can I use to determine the allocation unit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.