Problem mit Webserver Request
-
Hallo wieso antwortet hier der Server nicht mehr wenn ich ein 2tes mal Daten an den Server sende ?
send(kSock,edit.c_str(),strlen(edit.c_str()),0); cout<<"Request 2: " << endl; cout << edit.c_str(); cout<<endl; recv(kSock, buf3, 99999, 0); cout<<"Server antwort 2: " <<endl; cout<<endl; cout<< buf3 <<endl <<endl << endl; // <-- wieso bekomm ich keine request#include <windows.h> #include <iostream.h> #include <sstream> using namespace std; int main() { char buf2[99999]; char buf3[99999]; long rc = 0; int nret = 0; int ret = 0; string data = "login=123"; string req = "POST /seite2.php HTTP/1.1\r\n"; req+= "Host: testaccount435.te.funpic.de\r\n"; req+= "Referer: http://testaccount435.te.funpic.de\r\n"; req+="Content-type: application/x-www-form-urlencoded\r\n"; req+="Content-length: "; stringstream ccc; ccc<< data.length(); req+= ccc.str(); req+="\r\n"; req+= "Connection: close\r\n\r\n"; req+= data , "\r\n"; //------------------------------------------------------------------------------ string data_edit = "buffer=4"; string edit = "POST /seite3.php HTTP/1.1\r\n"; edit+= "Host: testaccount435.te.funpic.de\r\n"; edit+= "Referer: http://testaccount435.te.funpic.de\r\n"; edit+="Content-type: application/x-www-form-urlencoded\r\n"; edit+="Content-length: "; stringstream abc; abc<< data_edit.length(); edit+= abc.str(); edit+="\r\n"; edit+= "Connection: close\r\n\r\n"; edit+= data_edit , "\r\n"; SOCKET kSock; WSAData wsdata; WORD wsver=MAKEWORD(2, 0); nret = WSAStartup(wsver, &wsdata); if(nret != 0) { cout<<"Startup failed, error code: "<<WSAGetLastError(); WSACleanup(); return -1; } kSock = socket(AF_INET, SOCK_STREAM, 0); if(kSock == INVALID_SOCKET) { cout<<"Socket init failed"; return -1; } sockaddr_in sin; sin.sin_port=htons(80); sin.sin_addr.s_addr=inet_addr("213.202.225.64"); sin.sin_family=AF_INET; rc = connect(kSock,(sockaddr*)&sin, sizeof(sin)); if(rc==SOCKET_ERROR) { cout<<"Connect failed, error: "<<WSAGetLastError(); WSACleanup(); return -1; } else { cout<<"Verbindung erfolgreich! "<<endl<<endl; } send(kSock,req.c_str(),strlen(req.c_str()),0); cout<<"Request 1: " << endl; cout << req.c_str(); cout<<endl; recv(kSock, buf2, 99999, 0); cout<<"Server antwort 1: " <<endl; cout<<endl; cout<< buf2 <<endl <<endl << endl; cout<<"-----------------------------------------------------------"<<endl; send(kSock,edit.c_str(),strlen(edit.c_str()),0); cout<<"Request 2: " << endl; cout << edit.c_str(); cout<<endl; recv(kSock, buf3, 99999, 0); cout<<"Server antwort 2: " <<endl; cout<<endl; cout<< buf3 <<endl <<endl << endl; WSACleanup(); closesocket(kSock); system("PAUSE"); return 0; }
-
Was sicher falsch ist, ist dass Du recv(..) nicht aufrufst bis Du das hast was Du benötigst (z.B. die Antwort des WebServers).
Prüfe den Return Wert von recv(..), auch auf Fehler!
Simon