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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:54:06+00:00 2026-06-18T08:54:06+00:00

I’m experimenting with sockets and trying to build a very simple webbot. This is

  • 0

I’m experimenting with sockets and trying to build a very simple webbot.

This is my code:

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <cstring>
#include <iostream>
#include <string>

#define HTTP_PORT "80"

#define HOST "www.taringa.net"
#define PORT HTTP_PORT

#define IN_BUFFSIZE 1024
#define OUT_BUFFSIZE 1024

#define REQUEST "GET /Taringa/posts HTTP/1.0\r\nHost: www.taringa.net\r\nUser-Agent: foo\r\n\r\n"

using namespace std;

int main(int argc, char **argv) {

  struct addrinfo hints, *res;
  struct sockaddr_in servAddress;
  int sockfd;

  char addrstr[100];
  char buff_msg_out[OUT_BUFFSIZE], buff_msg_in[IN_BUFFSIZE];

  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ( getaddrinfo(HOST, HTTP_PORT, &hints, &res) != 0) {
     cerr << "Error en getaddrinfo" << endl;
     return -1;
  }


  // Crear socket
  if ( ( sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol) ) < 0 )
  {
   cerr << "Error en socket()" << endl;
   return -1;
  }


  // Iniciar conexion
  if ( connect(sockfd, res->ai_addr, res->ai_addrlen) == -1 )
  {
   cerr << "Error en connect()" << endl;
   cerr << "Error: " << strerror(errno) << endl;
   return -1;
  }

  cout << "Conectado con éxito" << endl;

  // Enviar datos
  strncpy(buff_msg_out, REQUEST, strlen(REQUEST));

  if ( send(sockfd, buff_msg_out, strlen(buff_msg_out), 0) <= 0 )
  {
   cerr << "Error en write()" << endl;
   return -1;
  }

  cout << "Mensaje enviado:" << endl << buff_msg_out << endl << endl;

  int bytes_recv = 0;

  while ( ( bytes_recv = recv(sockfd, buff_msg_in, IN_BUFFSIZE-1, 0)) > 0 )
  {
    buff_msg_in[bytes_recv] = '\0';
    cout << buff_msg_in << endl;        
  }

  freeaddrinfo(res);
  close(sockfd);

  return 0;
}

This is the output when the request has HTTP/1.0

HTTP/1.1 200 OK
Server: n0
Date: Fri, 01 Feb 2013 19:57:26 GMT
Content-Type: text/html; charset=utf8
Connection: close
Set-Cookie: trngssn=06359673; path=/
Set-Cookie: trngssn=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: taringa_user_id=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: lastNick=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: fbs=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: tws=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: iB-friendfind=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es" >
        <head profile="http://purl.org/NET/erdf/profile" prefix="og: http://ogp.me/ns
# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv=”X-Frame-Options” content=”Deny” />

                <link rel="alternate" type="application/atom+xml" title="Últimos Posts de Taringa" href="/rss/Taringa/posts/" />
                <link rel="alternate" type="application/atom+xml" title="Últimos Temas de Taringa" href="/rss/Taringa/tem
as/" />

                <title>Posts de Taringa!  - Taringa!</title>

…

    </body>
</html>

But when I specify HTTP/1.1, the reply is

HTTP/1.1 200 OK
Server: n0
Date: Fri, 01 Feb 2013 20:03:54 GMT
Content-Type: text/html; charset=utf8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: trngssn=81047255; path=/
Set-Cookie: trngssn=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: taringa_user_id=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: lastNick=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: fbs=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: tws=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net
Set-Cookie: iB-friendfind=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.taringa.net

d0f
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es" >
        <head profile="http://purl.org/NET/erdf
/profile" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv=”X-Frame-Options” content=”Deny” />

                <link rel="alternate" type="application/atom+xml" title="Últimos Posts de Taringa" href="/rss/Taringa/posts/" />
                <link rel="alternate" type="application/atom+xml" title="Últimos Te
mas de Taringa" href="/rss/Taringa/temas/" />

                <title>Posts de Taringa!  - Taringa!</title>

…

and here is the problem

    </body>
</html>

0

and it waits a few seconds before closing the communication.

I just tried with stackoverflow.com/about and it works fine. Except for the following text that the server sends me after the webpage

</html>HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

Am I missing something?

  • 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-18T08:54:07+00:00Added an answer on June 18, 2026 at 8:54 am

    Server: n0
    Date: Fri, 01 Feb 2013 20:03:54 GMT
    Content-Type: text/html; charset=utf8
    Transfer-Encoding: chunked
    Connection: keep-alive

    Don’t say you support HTTP 1.1 if you don’t.

    All HTTP/1.1 applications MUST be able to receive and decode the “chunked” transfer-coding, and MUST ignore chunk-extension extensions they do not understand. — HTTP 1.1

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.