PHP CURL发布请求和错误417

时间:2010-09-20 21:47:42

标签: 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);

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

Sooooorry因为我非常糟糕的英语

1 个答案:

答案 0 :(得分:11)

尝试添加此内容:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));