Thread: http post data to a website help

  1. #1
    Registered User
    Join Date
    Nov 2002

    http post data to a website help

    i am making a virus submitter tool that automatically checks files online
    here is the code, the problem is i am saying to keep the connection alive but after sending the identificador GET packet
    recv is coming back with 0 and connection close ,
    here is the actual packets live with a firefox addon called live htttp headers
    C++ pastebin - collaborative debugging tool, if someone could assist me on my project that would be great

    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    #pragma comment(lib , "WS2_32.lib")
    int _tmain(int argc, _TCHAR* argv[])
            //Inialize winsock to version 2.0
           WSADATA WSAdata;
            WSAStartup(MAKEWORD(2, 2), &WSAdata);
            //Resolve the website to get the ip
           unsigned long IP = inet_addr("");
            if (IP==INADDR_NONE) {
                   hostent *pHE = gethostbyname("");
                    if (pHE == 0)
                            return INADDR_NONE;
                    IP = *((unsigned long *)pHE->h_addr_list[0]);
            //Assign type ,port, ip
            sockaddr_in sins;
            sins.sin_family = AF_INET;
        sins.sin_port = htons(80);
            sins.sin_addr.s_addr = IP;
            SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
            //Connect to the resolved ip
            if(connect(sock, (sockaddr *)&sins, sizeof(SOCKADDR_IN))!= SOCKET_ERROR)
            char Buffer[50000];
        sprintf(Buffer,"GET / HTTP/1.1\r\n"
                                       "Keep-Alive: 300\r\n"
                                       "Connection: keep-alive\r\n\r\n");
            int Recvamount = 0;
            Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
            //Build the identificador GET packet
            sprintf(Buffer,"GET /vt/en/identificador HTTP/1.1\r\n"
                                       "Keep-Alive: 300\r\n"
                                       "Connection: keep-alive\r\n\r\n");
            //Send the identificador packet to website
            //Recv the data that came back from the site
           Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
    return 0;
    Last edited by Anddos; 08-24-2009 at 03:11 AM.

  2. #2
    Registered User
    Join Date
    Jan 2008

  3. #3
    Registered User
    Join Date
    Oct 2008
    I don't get the problem... you get the replies of the two requests just fine. True, it's not exactly proper HTTP, but in this case it happens to work.

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    I think he's posting because the header response he receives with his program doesn't match his browser (FireFox) shown by the plugin LiveHttpHeaders. He's right, I get the right headers here. Are you using a proxy? (looks like it - "Via" header, "X-Cache", "squid")

    Proxies tend to send back closed connections to the client, even though they will keep the connection open with whatever you request. Some proxies simply won't work with uploading. If you're using proxies, that's something you should have mentioned.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with HTTP POST
    By Anddos in forum Networking/Device Communication
    Replies: 5
    Last Post: 03-22-2009, 08:41 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Replies: 4
    Last Post: 07-31-2007, 05:31 PM
  4. Writing all HTTP requests from a website to a log file
    By goomyman in forum C# Programming
    Replies: 1
    Last Post: 07-29-2005, 09:18 AM
  5. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM