Okay so I finally decided to learn to use sockets yesterday.
Think I got the basics down lol.
Can someone point out why this doesn't work? I think it has more to do with http headers and formatting than sockets.

I don't think it POSTs properly and it GETs some pages but doesn't get others. If you have any ideas I will research them, preferably not dive into the 130 page RFC as this stage though.
CODE
#include "Socket.h"
#include <iostream>
#include <string.h>
using namespace std;
void getHPM(string &host,string &path, string &method, string &pdata){
cout << "Host? " << endl;
getline(cin,host);
if (host=="exit" || host=="newsocket") return;
cout << "Path? " << endl;
getline(cin,path);
cout << "Method? " << endl;
getline(cin,method);
if (method=="POST"){
cout << "Post Data? " << endl;
getline(cin,pdata);
}
}
int main(int g) {
cout << "g: " << g << endl;
string host;
string path;
string method;
string pdata;
getHPM(host,path,method,pdata);
SocketClient s(host.c_str(), 80);
while (host!="exit" && host!="newsocket"){
s.SendPartialLine(method.c_str());
s.SendPartialLine(" ");
s.SendPartialLine(path.c_str());
s.SendLine(" HTTP/1.1");
s.SendPartialLine("Host: ");
s.SendLine(host.c_str());
s.SendLine("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2");
s.SendLine("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
s.SendLine("Accept-Language: en-us,en;q=0.5");
//s.SendLine("Accept-Encoding: gzip,deflate");
s.SendLine("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
//s.SendLine("Referer: http://www.nexopia.com/usercomments.php?cachekey=AH68K1546F");
//s.SendLine("Cookie: flashInstalled=9.0 r28; userid=2294225; key=8b1518f916b47d47b02d3fb4f0d5afbd;");
if (method=="POST"){
s.SendLine("Content-Type: application/x-www-form-urlencoded");
s.SendPartialLine("Content-Length: ");
s.SendLine((char*)pdata.length());
s.SendLine("");
s.SendLine(pdata.c_str());
}
else
s.SendLine("");
while (1){
string res = s.ReceiveLine();
if (res.empty()) break;
cout << res;
cout.flush();
}
getHPM(host,path,method,pdata);
}
s.Close();
if (host=="newsocket") return 1;
else return 0;
}
And as you can see SendLine adds CRLF to what it sends. From what I can see you need one after a GET but it is forbidden after a POST? Oh damn lol. Might start in on the RFC after all.
Thanks for any insight.
This post has been edited by okyup: 1 Mar, 2007 - 06:39 PM