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

后端 未结 2 1528
悲&欢浪女
悲&欢浪女 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:00

    The responses header bit is separated from the content by a blank line.

    Need to take into account different line endings. Basically ignore \rs.

    So 1st read lines until you get a blank one then start printing them!

    EDIT

    You have a response as follows

    HTTP/1.1 200 OK
    Date: Fri, 20 Apr 2012 10:19:12 GMT
    ...
    Content-Type: text/html
    
    Hello World
    

    Notice that there is a blank line between the HTTP headers and the response (HTML in this case).

    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题