doxd96148 2014-08-14 10:43
浏览 39
已采纳

Onedrive上载因内部服务器错误而失败

I'm trying to create file on the OneDrive using REST API with PHP, but in the response I retrieve HTTP status code 500.

Code: `

    $url = $this->buildUrl(
        '{folder_id}/files/{filename}?access_token={token}',
        array(
            'folder_id' => $folderId,
            'filename'  => $filename,
            'token'     => $this->getAccessToken(),
        )
    );

    $response = wp_remote_request($url, array(
        'body'    => $content,
        'method'  => 'PUT',
    ));

`

Error message from the response body: An error occurred while performing the action. Try again later.

What i'm doing wrong?

  • 写回答

1条回答 默认 最新

  • dongmang3961 2014-08-28 22:03
    关注

    I just went through the same problem. It worked for me when I removed 'Content-type' line from request header.

    If you are using PHP Curl to send request in wp_remote_request, you can remove 'Content-type' line from request header by calling something similar to this, before calling curl_exec:

     curl_setopt($ci, CURLOPT_HTTPHEADER, array("Content-Type:"));
    

    By adding the code above, the actual request header looks like this (note there is no 'Content-Type'):

     PUT /v5.0/{folderId}/files/{filename}?access_token={accesstoken}
     User-Agent: SOMEAGENT
     Host: apis.live.net
     Accept: */*
     Expect: 100-continue
     Content-Length: 29
    

    FYI: I got a hint from here:

    http://msdn.microsoft.com/en-us/library/dn631834.aspx

    "For a PUT request, leave the Content-Type blank and put the contents of the file in the request body."

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?