这是我在发布文本数据时使用的内容(即name = Boxxy& age = 18)
ostream request_stream(&request);
request_stream << "POST " << path << " HTTP/1.0\r\n";
request_stream << "Host: " << host << "\r\n";
request_stream << "User-Agent: HTTPTool/1.0\r\n";
request_stream << "Content-Type: application/x-www-form-urlencoded\r\n";
request_stream << "Content-Length: " << data.length() << "\r\n";
request_stream << "Accept: */*\r\n";
request_stream << "Connection: close\r\n\r\n";
request_stream << data;
而且,在发布文件时,我试图使用它:
ifstream fin(file.c_str(), ios::binary);
ostringstream buffer;
buffer << fin.rdbuf();
string ctn(buffer.str());
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "POST " << path << " HTTP/1.0\r\n";
request_stream << "Host: " << host << "\r\n";
request_stream << "User-Agent: HTTPTool/1.0\r\n";
request_stream << "Content-Type: image/png\r\n";
request_stream << "Content-Disposition: attachment;name=file;filename=a.png\r\n";
request_stream << "Content-Length: " << ctn.length() << "\r\n";
request_stream << "Accept: */*\r\n";
request_stream << "Connection: close\r\n\r\n";
request_stream << ctn;
此代码返回1,但PHP端没有任何反应。我也尝试使用PUT而不是POST。和不同的内容类型。我的标题有问题,还是我应该做一些与普通POST请求不同的事情?