Send Http “Post” Request To Php Code in C or C++

后端 未结 2 1567
悲&欢浪女
悲&欢浪女 2021-01-15 08:49

I\'m trying to send a \"post\" reguest to my php file and get the info back, it works fine, but

it also print something before printing my response from the php fil

2条回答
  •  悲&欢浪女
    2021-01-15 09:10

    First part of the response you received is made up of HTTP version, Server Response Status Code and various HTTP response headers.

    HTTP/1.1 200 OK Date: Fri, 20 Apr 2012 10:19:12 GMT Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 X-Powered-By: PHP/5.3.6 Content-Length: 12 Connection: close Content-Type: text/html

    After headers follows HTTP response body (which you need to extract):

    hello world

    HTTP headers and body are separated with the following sequence of characters: \r\n\r\n. So all you need to do is to search for it and extract everything that is behind it.

    You can do this yourself (sockets, parsing...) but my advice is to use some of HTTP libraries: WinInet, WinHttp (both are Microsoft's) or libCurl (open source).

提交回复
热议问题