Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
P

Peter Laursen

@Peter Laursen
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • WinSOCK and HTTP POST - how to send/receive data?
    P Peter Laursen

    Thanks for the replies, all of you. Neil, your headers worked beautifully if I sent them as-is. However, whenever I try to do something complicated like asking the user to type in his name and then change the Content-Length parameter accordingly, the server sends back a 0... Here is the new snippet I have been adding: connect(MySocket, (struct sockaddr*)&Server, sizeof(struct sockaddr)); string Send("POST /Test.php HTTP/1.1\r\nHost: tdlgames.com:80\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded\r\n"); cout << "Enter your name: "; string Name; getline(cin, Name); char Content[100]; sprintf(Content, "Content-Length: %d\r\n\r\n", Name.length()); Send += Content; Send += "Name="; Send += Name; send(MySocket, Send.c_str(), Send.length(), 0); ... The receive code has not changed. Please help me a bit more - I am grateful for all the answers. Thank you, Peter. Visit http://www.tdlsoftware.com

    C / C++ / MFC help tutorial php com sysadmin

  • WinSOCK and HTTP POST - how to send/receive data?
    P Peter Laursen

    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: Please help, Peter --Code-- #include #include #include #include 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.

    C / C++ / MFC help tutorial php com sysadmin
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups