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 7417345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:41:00+00:00 2026-05-29T07:41:00+00:00

Recently I wrote a program using sockets in C, to connect to an HTTP

  • 0

Recently I wrote a program using sockets in C, to connect to an HTTP server running locally and thereby to do requests to that.

That worked fine for me. After that I tried the same code to connect to another server on the web (e.g. http://www.google.com), but I was not able to connect and was getting another html response from the proxy server in my network.

  • My local IP is: 10.0.2.58
  • The proxy IP is: 10.0.0.1

This is the response I got :

HTTP/1.1 302 Found
Expires: Fri, 10 Feb 2012 12:47:35 GMT
Expires: 0
Cache-Control: max-age=180000
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Location: http://10.0.0.1:8000/index.php?redirurl=http%3A%2F%2F10.0.2.58%2F
Content-type: text/html
Content-Length: 0
Date: Wed, 08 Feb 2012 10:47:35 GMT
Server: lighttpd/1.4.29

How can I bypass this proxy to connect to external servers?


Response got when tried with CONNECT

HTTP/1.1 302 Found
Expires: Fri, 10 Feb 2012 13:37:58 GMT
Expires: 0
Cache-Control: max-age=180000
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Location: http://10.0.0.1:8000/index.php?redirurl=http%3A%2F%2F10.0.2.58http%3A%2F%2Fwww.google.com%2F
Content-type: text/html
Content-Length: 0
Date: Wed, 08 Feb 2012 11:37:58 GMT
Server: lighttpd/1.4.29

Working code which connect’s to my local apache

#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>
#include<string.h>

#define MAX_BUFFER_SIZE 1024

int main(int argc,char *argv[])
{
  int clsd,ssd,status;
  char buffer[1024];
  char request[]="GET / HTTP/1.1\r\nHost:10.0.2.58\r\n\r\n";
  struct sockaddr_in srvr_addr;

  struct addrinfo hints,*res;

  srvr_addr.sin_family=AF_INET;
  srvr_addr.sin_port=htons(80);
  srvr_addr.sin_addr.s_addr=inet_addr("10.0.2.58");//Local server

  clsd =socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  if(clsd<=0)
  {
        perror("Socket init failed..\n");return 1;
  }
  ssd=connect(clsd,(struct sockaddr *)&srvr_addr,(socklen_t)(sizeof srvr_addr));
  if(clsd<=0)
  {
        perror("Socket connect failed..\n");return 1;
  }
  write(clsd,request,strlen(request));
  memset((void *)&request,0x00,strlen(request));
  memset(&buffer,0x00,MAX_BUFFER_SIZE);

 do
 {
  status=read(clsd,&buffer,MAX_BUFFER_SIZE);
  write(1,&buffer,status);
 memset((void *)&request,0x00,strlen(request));
  memset(&buffer,0x00,MAX_BUFFER_SIZE);

 do
 {
  status=read(clsd,&buffer,MAX_BUFFER_SIZE);
  write(1,&buffer,status);
 }while(status>0);
 close(clsd); 
 return 0;
}
  • 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-29T07:41:01+00:00Added an answer on May 29, 2026 at 7:41 am

    To use connections via proxy (or if they are implicitly proxy-fied), first you should connect to proxy, send a ‘CONNECT’ message with target host; proxy will establish connection and return you data.

    Here is in steps:

    1. open socket to proxy host
    2. send ‘CONNECT http://www.google.com:80 HTTP/1.0\r\n\r\n‘ string
    3. wait for recv

    You must specify protocol (in our case is HTTP 1.0, non-chunked) with ending newline characters, so proxy knows how to communicate with end point.

    You can find details about CONNECT method at http://www.ietf.org/rfc/rfc2817.txt

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

Sidebar

Related Questions

I recently wrote a program that used a simple producer/consumer pattern. It initially had
I recently wrote a small number-crunching program that basically loops over an N-dimensional grid
I have been looking at Reflection.Emit recently. I wrote a simple program that generates
I recently wrote a program to solve the backpack problem using python. It works
I recently wrote a parser in Python using Ply (it's a python reimplementation of
I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I recently wrote some javascript code that filled a drop down list based on
I recently wrote some data access methods (plain old Java) that use immutable objects
I recently wrote the following C code using sysinfo systemcall to display system statistics,
I recently wrote a post: Weird Error in C++ Program: Removing Printout Breaks Program

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.