ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: denf@novosoft.ru
To: mandrake-russian@linuxteam.iplabs.ru
Subject: Re: [mdk-re] HTTP, c++  и Linux
Date: Tue Dec 12 15:39:01 2000
Message-ID: <OF1C3AF9FB.72662D7B-ONC62569B3.0044D80D@novosoft.ru> (raw)


Добрый день!

12/12/2000 05:34:36 PM mandrake-russian-admin wrote:
>Здравствуйте, Господа!
>
>Сразу  хочу  извиниться  за  оффтопик,  но, к сожалению, не смог найти
>нужную  мне  информацию  в  других местах. Здесь, вероятно, есть много
>программистов.  Может  кто-нибудь  мне подскажет, как на Си под Линукс
>написать  программу, которая соединяется в WWW сервером на 80-ом порту
>и  посылает  туда  запросы  (GET,  POST).  Или  посоветуйте, где можно
>что-нибудь  почитать  на  эту  тему. А, может быть, у кого-нибудь есть
>что-нибудь  похожее.  Ответ сервера сохранять не нужно, важен сам факт
>подачи запроса. Пожалуйста помогите, очень нужно.

Примерно вот так:

    const char hostname[] = "localhost";
    struct sockaddr_in addr;
    int sock;
    char result[1024];
    FILE *conn;

    struct hostent* host = gethostbyname( hostname );
    sock = socket( PF_INET, SOCK_STREAM, IPPROTO_IP );

    addr.sin_port = htons(80);
    addr.sin_addr.s_addr = *(unsigned long*) host->h_addr;
    addr.sin_family = AF_INET;

    if ( connect( sock, (struct sockaddr*) &addr, sizeof(addr) ) ) {
        perror( "cannot connect()" );
        exit(1);
    }

// соединение установлено, можно писать/читать различными способами
(send/recv) или (write/read). Ответ сервера надо прочитать, даже если он не
нужен.

    conn = fdopen( sock, "r+" );

    fprintf( conn, "GET / HTTP/1.0\n\n" );
    fflush( conn );

    while( !feof(conn) ) {
        fgets( result, sizeof(result), conn );
        printf( "%s", result );
    }

    fclose( conn );

С уважением,
Денис.

             reply	other threads:[~2000-12-12 15:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-12 15:39 denf [this message]
2000-12-12 16:08 ` [mdk-re] Re[2]: " Roman Shumikhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OF1C3AF9FB.72662D7B-ONC62569B3.0044D80D@novosoft.ru \
    --to=denf@novosoft.ru \
    --cc=mandrake-russian@linuxteam.iplabs.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git