biprinea biprinea - 1 year ago 68
PHP Question

What is my "Request header"?

I'm beginner in socket programming now I want to send a request like

this is a test
to server and receive it in the server.

I use a MSDN sample code to connect to server and send a buffer to server but I don't know How the request header should be?


Answer Source

You should form a request string and send that string to the server. For example if your server accepts query string like this

http://localhost/test.php?input=this is a test

which is equivalent to


You would form a request like this:

"GET /test.php?input=this%20is%20a%20test HTTP/1.1\r\nConnection: Close\r\nHost: localhost\r\n\r\n""

You should also read the response code sent by the server if you want to know if it succeeded or not.

This is the server response from my machine:

HTTP/1.1 200 OK
Date: Sun, 02 Oct 2016 12:01:12 GMT
Server: Apache/2.4.17 (Win64) PHP/5.6.16
X-Powered-By: PHP/5.6.16
Content-Length: 14
Connection: close
Content-Type: text/html; charset=UTF-8

this is a test

from test.php file


    echo $_GET["input"];
    echo "Didn't get any query string";

Let me know if that helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download