Click here to Skip to main content
15,890,506 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhat is the max length of tree branche? Pin
bilas15-Feb-05 7:52
bilas15-Feb-05 7:52 
AnswerRe: What is the max length of tree branche? Pin
rocky_pulley15-Feb-05 9:03
rocky_pulley15-Feb-05 9:03 
GeneralRe: What is the max length of tree branche? Pin
bilas15-Feb-05 11:03
bilas15-Feb-05 11:03 
Generalcheck if PC connects to the internet Pin
includeh1015-Feb-05 5:49
includeh1015-Feb-05 5:49 
GeneralRe: check if PC connects to the internet Pin
Ravi Bhavnani15-Feb-05 8:58
professionalRavi Bhavnani15-Feb-05 8:58 
GeneralRe: check if PC connects to the internet Pin
David Crow15-Feb-05 10:57
David Crow15-Feb-05 10:57 
GeneralRe: check if PC connects to the internet Pin
includeh1015-Feb-05 22:48
includeh1015-Feb-05 22:48 
QuestionWinSOCK and HTTP POST - how to send/receive data? Pin
Peter Laursen15-Feb-05 5:08
Peter Laursen15-Feb-05 5:08 
Hi everyone,
I have asked on several programming forums and googled for weeks, but I am unable to find just exactly how to send and receive data from a client to a webserver.
What I need is a simple example on how to send a POST request to a webserver using WinSock. (Form data name=YourName&Age=20)
This code should (if I understand everything correctly) work, yet it does not. Whenever the server gets back to me, all it gives me is a 0.
Here is the simple PHP script I use for testing:
<?php
print($_POST["Name"]);
?>
Please help,
Peter
--Code--
#include <iostream>
#include <string>
#include <cstdlib>
#include <winsock.h>
using namespace std;
int main() {
WSADATA WSAData;
WSAStartup(MAKEWORD(1,1), &WSAData); // Someone told me to use the lowest version of Winsock that satisfied my needs
struct hostent* Host;
struct sockaddr_in Server;
Server.sin_family = AF_INET;
Server.sin_port = htons(80);
Host = gethostbyname("tdlgames.com"); // One of my websites. Uses the Apachee webserver on a Linux platform.
Server.sin_addr = *((struct in_addr*)Host->h_addr);
SOCKET MySocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connect(MySocket, (struct sockaddr*)&Server, sizeof(struct sockaddr));
string SendInfo("POST /Test.php http/1.1\r\nHost: tdlgames.com\r\nUser-Agent: TestPostMethod/1.0\r\nContent-Type: application-www-form-urlencoded\r\n\r\nName=Peter");
// Eventually, the error might be in the things I send - again, please advise on what to do...
int BytesSent = send(MySocket, SendInfo.c_str(), SendInfo.length(), 0);
char Buffer[1024];
while (recv(MySocket, Buffer, 1023, 0))
cout << Buffer << endl;
closesocket(MySocket);
WSACleanup();
system("pause");
}
---
Thanks for reading.



AnswerRe: WinSOCK and HTTP POST - how to send/receive data? Pin
Ravi Bhavnani15-Feb-05 9:01
professionalRavi Bhavnani15-Feb-05 9:01 
GeneralRe: WinSOCK and HTTP POST - how to send/receive data? Pin
humps15-Feb-05 9:44
humps15-Feb-05 9:44 
GeneralRe: WinSOCK and HTTP POST - how to send/receive data? Pin
Peter Laursen16-Feb-05 0:05
Peter Laursen16-Feb-05 0:05 
GeneralRe: WinSOCK and HTTP POST - how to send/receive data? Pin
humps16-Feb-05 9:09
humps16-Feb-05 9:09 
General#include &amp; Enviornment variables Pin
BlueCrack15-Feb-05 5:04
BlueCrack15-Feb-05 5:04 
GeneralHelp changing the position of the text cursor in an edit box Pin
Bi0Mutati0n15-Feb-05 5:01
Bi0Mutati0n15-Feb-05 5:01 
GeneralRe: Help changing the position of the text cursor in an edit box Pin
basementman15-Feb-05 5:38
basementman15-Feb-05 5:38 
GeneralRe: Help changing the position of the text cursor in an edit box Pin
Bi0Mutati0n15-Feb-05 6:04
Bi0Mutati0n15-Feb-05 6:04 
GeneralRe: Help changing the position of the text cursor in an edit box Pin
Blake Miller15-Feb-05 6:19
Blake Miller15-Feb-05 6:19 
Generalauto login website Pin
ThinkingPrometheus15-Feb-05 3:50
ThinkingPrometheus15-Feb-05 3:50 
GeneralRe: auto login website Pin
Ravi Bhavnani15-Feb-05 9:05
professionalRavi Bhavnani15-Feb-05 9:05 
GeneralRe: auto login website Pin
ThinkingPrometheus15-Feb-05 20:09
ThinkingPrometheus15-Feb-05 20:09 
GeneralRe: auto login website Pin
Ravi Bhavnani16-Feb-05 2:06
professionalRavi Bhavnani16-Feb-05 2:06 
GeneralRe: auto login website Pin
humps15-Feb-05 9:49
humps15-Feb-05 9:49 
Questionwin32: SetSysColors for a single window/process? Pin
cybertank15-Feb-05 3:44
cybertank15-Feb-05 3:44 
AnswerRe: win32: SetSysColors for a single window/process? Pin
rocky_pulley15-Feb-05 4:31
rocky_pulley15-Feb-05 4:31 
Generalstop sub process Pin
includeh1015-Feb-05 2:50
includeh1015-Feb-05 2:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.