cURL C ++发布数据错误

时间:2018-08-01 22:59:23

标签: php c++ curl post libcurl

我正在尝试使用C ++中的cURL将发布数据发送到PHP脚本。 我的PHP脚本包括:

<?php
    echo "post data ''test'': ";
    echo $_POST[ "test" ];
    echo "\nget data ''test'': ";
    echo $_GET[ "test" ];
?>

我在C ++中的函数如下:

std::string PX_API Request( const std::string& strSite )
{
    std::string strResponseBuffer;

    curl_easy_setopt( pConnection, CURLOPT_URL, strSite.c_str( ) );
    curl_easy_setopt( pConnection, CURLOPT_POST, true );
    curl_easy_setopt( pConnection, CURLOPT_POSTFIELDS, "test=post" );
    curl_easy_setopt( pConnection, CURLOPT_FOLLOWLOCATION, true );
    curl_easy_setopt( pConnection, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT );
    curl_easy_setopt( pConnection, CURLOPT_USERAGENT, "libcurl-agent/1.0" );
    curl_easy_setopt( pConnection, CURLOPT_WRITEFUNCTION, WriteCallback );
    curl_easy_setopt( pConnection, CURLOPT_WRITEDATA, &strResponseBuffer );

    dbg::Assert( curl_easy_perform( pConnection ) == CURLE_OK );
    return strResponseBuffer;
}

我这样称呼它:

const auto strResponse = Request( "https://*.*/script.php?test=get" );

当我将其打印到控制台时,输出如下:

post data ''test'':
get data ''test'': get

如您所见,脚本能够获取$ _GET数据,但不能获取$ _POST。 我不确定为什么会发生这种情况,我一直在寻找解决方案,但没有找到能解决问题的方法。这在我拥有的没有SSL的其他网站上可以正常工作。我不知道SSL是否是问题。我已经尝试明确说明端口:443,但这没有什么不同。我尝试过使用和不使用useragent,设置和不设置sslversion,设置它从中定向的页面,等等。

在此先感谢所有回复的人。

0 个答案:

没有答案