Follow us on Twitter!
It is never to LATE to become what you never WERE.
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 17
Guests Online: 15
Members Online: 2

Registered Members: 82889
Newest Member: Geriztul
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

c++ sockets, POST'ing


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 31-01-06 23:12
Code
#include <stdio.h>
#include "winsock2.h"
#include <iostream>
#include <fstream>
#include <windows.h>


using namespace std;
int main(int argc, char *argv[]) {
   
    // MessageBox(NULL, "hallo", "socketIndication", MB_OK);
   
    // Initialize Winsock.
    WSADATA wsaData;
    int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
    if ( iResult != NO_ERROR )
        printf("Error at WSAStartup()\n");

    // Create a socket.
    SOCKET m_socket;
    m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

    if ( m_socket == INVALID_SOCKET ) {
        printf( "Error at socket(): %ld\n", WSAGetLastError() );
        WSACleanup();
        return 1;
    }

    // Connect to a server.
   
   
    LPHOSTENT hostEntry;
    hostEntry = gethostbyname(argv[1]);   
   
    sockaddr_in clientService;
    clientService.sin_family = AF_INET;       
    clientService.sin_addr =  *((LPIN_ADDR)*hostEntry->h_addr_list); // inet_addr("127.0.0.1");
    clientService.sin_port = htons( 80 );

    if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
        printf( "Failed to connect.\n" );
        WSACleanup();
        return 1;
    }

    // Send and receive data.   
   
    if(argc!=3)
    {
               cout<<"Usage:connect_web www.sau.no /index.html";
               return 1;
}

    char sendbuf[2000]="POST ";
   
    strcat(sendbuf, argv[2]);
    strcat(sendbuf, " HTTP/1.1\r\nHost: ");
    strcat(sendbuf, argv[1]);
    strcat(sendbuf, "\r\nUser-Agent: who_cares?\r\n");
    strcat(sendbuf, "Referer: google.com\r\n");
    strcat(sendbuf, "Connection: close\r\n");
   
    strcat(sendbuf, "Content-Type: application/x-www-form-urlencoded\r\n");
    strcat(sendbuf, "Content-Length: 17\r\n");
   
    strcat(sendbuf, "from=faen&submit=\r\n\r\n");
    // strcat(sendbuf, "submit=\r\n\r\n");
   
   
    cout<< sendbuf << "\n";
    char recvbuf[100];
    int bytesRecv;
   
    send( m_socket, sendbuf, strlen(sendbuf), 0 );
   
   
    while(bytesRecv!=SOCKET_ERROR)
    {
    bytesRecv=recv( m_socket, recvbuf, strlen(recvbuf), 0 );
    if(!bytesRecv)
    { break; }
   
     
    cout.write(recvbuf, strlen(recvbuf));
    } 
   
    WSACleanup();
    return 1;
     }





Why isnt it working? It should work.

EDIT: Damn smilies
[edit Grind]No smileys[/edit]

Edited by on 16-03-06 00:00
Author

RE: c++ sockets, POST'ing


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-02-06 15:16
Hey,
I had this prob when I was sending data with POST in PHP. You need the two \r\n 's after the CONTENT-LENGTH and NOT after the content. So the code would be:
Code

....
strcat(sendbuf, "Content-Length: 17\r\n\r\n");
strcat(sendbuf, "from=faen&submit=\r\n\r\n");
....




I think that should work. BTW, you just check the 'disable smileys' checkbox when posting the message to disable the smileys like I am doing.

Thomas
Author

RE: c++ sockets, POST'ing


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-03-06 22:40
Thank you so much, you have no idea of how much time i've spent finding it out.