I have a problem in my code I did send HTTP request to facebook server but the problem i get HTTP/1.1 301 Moved Permanently message. What i want to do is to allow follow the header response link and give me the redirected page HTML, Also I tried to send another HTTP request but I get no response so i thought there is function option that allow me to follow the header link.
So basically what i'm trying to do is this send http post request to facebook server with my user and password log in follow header redirect link give me response.
if it's possible please guide me to the right way to do it. PS: I already read some RFC and it's still not clear. Thanks for your time.
My code
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
int sockid, status;
unsigned strSize;
ssize_t count; //
struct sockaddr_in addr; // struct
ssize_t size = sizeof(addr);
sockid = socket(PF_INET, SOCK_STREAM, 0); // create socket
if(sockid < 0) //if error
{
cout<<"Cannot create sucket\n";
close(sockid);
exit(EXIT_FAILURE);
}
// access struct
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
if(inet_aton("31.13.90.36",&addr.sin_addr) == 0)
{
cout << "Wrong address";
close(sockid);
exit(-1);
}
status = connect(sockid, (sockaddr*)&addr, sizeof(addr)); // attempt to establish a connection
// check
if(status < 0)
{
cout << "failed to establish a connection";
close(sockid);
exit(EXIT_FAILURE);
}
// sending HTTP request
char msg[] = "POST /login.php HTTP/1.1\r\n"
"HOST: m.facebook.com\r\n"
"Content-type: application/x-www-form-urlencoded\r\n"
"Content-Length: 147\r\n"
"Connection: Keep-Alive\r\n"
"\r\n"
"lsd=AVp5UV4F&version=1&ajax=0&width=0&pxr=0&gps=0&dimensions=0&m_ts=1481464104&li=KFlNWFL78UFJkrUnTV_sFFDQ&email=Minglixe&pass=test123&login=Log+In";
const int bufSize = 4000;
char * buf;
buf = new char [bufSize];
//unsigned bufSize = strlen(buf);
strSize = strlen(msg);
send(sockid, msg, strSize, 0); // send request
while((count = recv(sockid, buf, bufSize, 0)) > 0)// receive the request
{
buf[count] = '\0';
cout << buf << flush;
}
if(count < 0 )
{
cout << "error" ;
exit(EXIT_FAILURE);
}
delete[] buf;
close(sockid);
}