Home > Backend Development > PHP Tutorial > upyun 刷新缓存的签名不知道哪错了

upyun 刷新缓存的签名不知道哪错了

WBOY
Release: 2016-06-06 20:34:33
Original
1078 people have browsed it

返回的结果是401 Sign error

<code>public function delete($path) {
    //比如http://www.xx.com/a/b.jpg,我传过来删除的就是/a/b.jpg
    //删除部分略过
    //刷新缓存开始
    $ch = curl_init('http://purge.upyun.com/purge/');
    $date = gmdate('D, d M Y H:i:s \G\M\T');

    //这里签名我是直接用的$path,我是怀疑这里错了 但是我试过http://www.xx.com加在前面也还是错误
    $sign = md5($path.'&'.$this->bucket.'&'.$date.'&'.md5($this->password));

    //头信息
    $header = array(
        'Expect: ""',
        'Authorization: UpYun '.$this->config['bucket'].':'.$this->config['username'].':'.$sign,
        'Date: '.$date,
        'Content-Type: application/x-www-form-urlencoded',
    );
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);

    //POST方式
    curl_setopt($ch,CURLOPT_POST,1);

    //这里也是个问题,我不知道这个要不要提交过去
    $data = array(
        'purge' => urlencode($path),
    );
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

    //是否返回头信息
    curl_setopt($ch,CURLOPT_HEADER,1);

    $response = curl_exec($ch);

    $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);

    //打印结果
    var_dump($response);
}
</code>
Copy after login
Copy after login

回复内容:

返回的结果是401 Sign error

<code>public function delete($path) {
    //比如http://www.xx.com/a/b.jpg,我传过来删除的就是/a/b.jpg
    //删除部分略过
    //刷新缓存开始
    $ch = curl_init('http://purge.upyun.com/purge/');
    $date = gmdate('D, d M Y H:i:s \G\M\T');

    //这里签名我是直接用的$path,我是怀疑这里错了 但是我试过http://www.xx.com加在前面也还是错误
    $sign = md5($path.'&'.$this->bucket.'&'.$date.'&'.md5($this->password));

    //头信息
    $header = array(
        'Expect: ""',
        'Authorization: UpYun '.$this->config['bucket'].':'.$this->config['username'].':'.$sign,
        'Date: '.$date,
        'Content-Type: application/x-www-form-urlencoded',
    );
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);

    //POST方式
    curl_setopt($ch,CURLOPT_POST,1);

    //这里也是个问题,我不知道这个要不要提交过去
    $data = array(
        'purge' => urlencode($path),
    );
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

    //是否返回头信息
    curl_setopt($ch,CURLOPT_HEADER,1);

    $response = curl_exec($ch);

    $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);

    //打印结果
    var_dump($response);
}
</code>
Copy after login
Copy after login

$path 后面加 \n,类似:http://www.xx.com/a/b.jpg\n

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template