使用 c++ 发布 html 页面

Posting a html page using c++

本文关键字:页面 html 发布 c++ 使用      更新时间:2023-10-16

我正在尝试使用c ++发布一个html页面。我使用实现 tcpsoketing 的套接字构建了一个类。我检查了一下,它起作用了。所以我认为我的问题出在我发送的内容上:

string s = "<!DOCTYPE html><html><head><title>home.html</title></head><body><form name='input' action='login.html' method='get'>user name: <input type='text' name='user'><br>password: <input type='text' name='password'><input type='submit' value='Submit'> </form></body></html>";
string str="POST /home.html HTTP/1.1rnHost: 127.0.0.1:22225rnUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.66 Safari/537.36rnAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8rnAccept-Language: en-US,en;q=0.8Accept-Encoding: gzip,deflate,sdchrnrnrnrnConnection: keep-alivernContent-Type: application/x-www-form-urlencodedrnContent-Length: 2048"+s;

你的怀疑是正确的。您的请求消息格式不正确。请参阅 RFC 7230,第 3 节:https://www.rfc-editor.org/rfc/rfc7230#section-3

 HTTP-message   = start-line
                  *( header-field CRLF )
                  CRLF
                  [ message-body ]

密切注意每个标题字段后需要使用多少行尾。

提示:标头块和消息正文用 CRLF CRLF 分隔。

确保在标题和正文之间有一个空行(在 RFC 7230 中指定),例如

HTTP/1.1 200 OK
Server: Apache/1.3.29 (Unix) PHP/4.3.4
Content-Length: 123456
Content-Language: de
Connection: close
Content-Type: text/html
<!DOCTYPE html><html></html>