PHP CURL发布请求和错误417

Isi*_*sis 4 php curl

function query($url, $pfields = 0, $cookie = 0)
{
    curl_setopt($ch, CURLOPT_HEADER, 1);
    if (!empty($pfields))
    {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $pfields);
    }            
    if (!empty($cookie))
    {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);            
    }            
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_ENCODING,'gzip');
    if (!$login)
    {
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }
    $content = curl_exec($ch);
    return $content;
}

$cookie = 'sessionID=3864cab58412ec567b634db3c317898;OAGEO=RU%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C;';
$p = '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++';
$post = 'clientid=23&campaignid=52&bannerid=111&appendsave=1&appendtype=0&append=' . urlencode($p) . '&submitbutton=';

echo query('http://example.com/in.php', $post, $cookie);
Run Code Online (Sandbox Code Playgroud)

此代码返回417错误(但是$ p不是使用urlencode但是IS OK但是+(加)更改为""(空格)

Sooooorry因为我非常糟糕的英语

Mat*_*hew 11

尝试添加此:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
Run Code Online (Sandbox Code Playgroud)

  • @Nate,Curl自动为"大"帖子添加Expect/100-Continue标题.简而言之,这允许客户端在发布大量数据之前向服务器请求许可.(即,如果服务器要拒绝您的请求,为什么要发布数据?)某些服务器,特别是lighttpd,不支持这种情况,而不是静默失败,它们会产生错误.上面的代码只是清除了标题并发送了一个常规请求. (2认同)