http post data to a website help

This is a discussion on http post data to a website help within the C++ Programming forums, part of the General Programming Boards category; i am making a virus submitter tool that automatically checks files online here is the code, the problem is i ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    315

    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

    Code:
    #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("virustotal.com");
    
            if (IP==INADDR_NONE) {
       
                   hostent *pHE = gethostbyname("virustotal.com");
    
                    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)
    
            {
    
                    printf("%s\n","Connected:");
    
            }
    
     
    
            char Buffer[50000];
    
        sprintf(Buffer,"GET / HTTP/1.1\r\n"
    
                               "Host: www.virustotal.com\r\n"
    
                                       "Keep-Alive: 300\r\n"
    
                                       "Connection: keep-alive\r\n\r\n");
    
     
    
           
    
            send(sock,Buffer,strlen(Buffer),0);
    
           
    
            int Recvamount = 0;
    
            memset(Buffer,0,sizeof(Buffer));
    
            Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
    
            printf("%s\n",Buffer);
    
     
    
     
    
            memset(Buffer,0,sizeof(Buffer));
    
            //Build the identificador GET packet
    
            sprintf(Buffer,"GET /vt/en/identificador HTTP/1.1\r\n"
    
                               "Host: www.virustotal.com\r\n"
    
                                       "Keep-Alive: 300\r\n"
    
                                       "Connection: keep-alive\r\n\r\n");
    
     
    
            //Send the identificador packet to website
    
            send(sock,Buffer,strlen(Buffer),0);
    
     
    
            //Recv the data that came back from the site
    
            memset(Buffer,0,sizeof(Buffer));
    
           Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
           printf("%s\n",Buffer);
    
    return 0;
    }
    Attached Images Attached Images  
    Last edited by Anddos; 08-24-2009 at 03:11 AM.

  2. #2
    EOP
    EOP is offline
    Registered User
    Join Date
    Jan 2008
    Posts
    45

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    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
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    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, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21