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

  • SEARCH
  • Home
  • 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 8766775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:38:07+00:00 2026-06-13T16:38:07+00:00

I need to build an HTTP Proxy Server that handle GET method. I am

  • 0

I need to build an HTTP Proxy Server that handle GET method.
I am able to establish an connection from Client(web brownser) to Proxy Server and Proxy is Sending Reformatted header to Server and retrieve the reponse.
But the proxy is not receiving entire data.

My code is as follows:

main(int argc,char **argv)
 {
//Server binds to particular port
//Waiting for connection");
for(;;)
{
     //Connect to client
    handle_connection(connfd,&cli_addr);
    close(connfd);

}
}
void handle_connection(int connfd, struct sockaddr_in *cli_addr)
{
struct sockaddr_in host_addr;
char buffer[BUFFSIZE];
int rfd,n;
char** http_args;
url* requested_url;
struct hostent *hp;

bzero(buffer, BUFFSIZE);

if ((rfd = read(connfd,buffer,BUFFSIZE)) < 0 ) {
    perror("Error reading from socket.");
    return;
}
buffer[rfd]='\0';

split_line( (char*)buffer, (char**)http_args,2);
requested_url = parse_request(http_args[1]);

//Printing
    printf("\nCommand: %s\n", http_args[0]);
    printf("Url: %s\n", http_args[1]);
    printf("proto: %d\n",requested_url->proto);
    printf("port: %d\n",requested_url->port);
    printf("host: %s\n",requested_url->host);
    printf("File: %s\n",requested_url->file);


if((strcmp(http_args[0],"GET"))!=0)
{
printf("here");
http_error_messages(connfd, http_args[0], 501, "Not Implemented","Proxy does not implement this method");
return;
}

//Connection to request made to server on rfd 
sprintf(buffer, "%s %s HTTP/1.%d\r\nHost: %s:80\r\n\r\n"
        , http_args[0], requested_url->file, requested_url->proto, requested_url->host);
printf("In the Server %s",buffer);
//printf("In the Server %s",get_header);
n = write(rfd,buffer,sizeof(buffer));
shutdown(rfd,2);

char buff[MAXLINE];
while((n = read(rfd, buff, MAXLINE)) > 0) {
    write(connfd, buff, MAXLINE);
    printf("%s",buff);
    }
    if(n<0)
    {
    perror("Error in reading");
    }
    shutdown(rfd,1);
    shutdown(connfd,2);

close(rfd); 

 }
  • 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-06-13T16:38:09+00:00Added an answer on June 13, 2026 at 4:38 pm

    On TCP sockets you’ll need to call read() repeatedly until the expected terminating character (\n?) is read, or the required number of bytes has been read.

    read() can return partial or no data, depending on how TCP packets get segmented/buffered/messed with.

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

Sidebar

Related Questions

The problem is I need to build a web service client from a file
I need web access from Gradle through a proxy server to use the Gradle/Artifactory
I need to build a web-scale public site that can handle, say, 100 queries/sec.
I need to build a web service to handle HTTP Form posts (CRUD) using
I have a Silverlight client that I need to call a web service. The
I need to build a local fake http server. It will listen all my
I need to build a simple HTTP server in C. Any guidance? Links? Samples?
I have the following fiddle1 http://jsfiddle.net/y6tCt/35/ . I need to build the checkbox list
I need to build some client side code which follows this use case: An
I need to build a multidimensional array from records retrieved from my database. Here

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.