HTTP Post请求遇到错误? [英] Getting error with a HTTP Post request?

查看:520
本文介绍了HTTP Post请求遇到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用于OneDrive文件访问的新共享链接.

I am trying create a new share link for onedrive file access.

这是我应该做的,

POST /drive/items/{item-id}/action.createLink
Content-Type: application/json

{
"type": "view"
}

我已经在ruby中创建了一个发帖请求,如下所示,

I have created a post request in ruby as follow,

require 'net/http'
require 'json'

uri = URI.parse("https://api.onedrive.com/v1.0")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new("https://api.onedrive.com/v1.0/drive/items/file.88e469b2d4c51142.88E469B2D4C51142!113/action.createLink")
req.content_type = "application/json"   
json = {:type=> "view"}.to_json   
req.body = json
response = http.request(req)
puts response.body
puts response

通过运行上面的代码,我得到以下错误为JSON,

By running the above code I am getting the following error as JSON,

{
"error": {
"code": "invalidArgument",
"message": "ObjectHandle is Invalid",
"innererror": {
  "code": "badArgument",
  "innererror": {
    "code": "invalidObjectHandle",
    "innererror": {
      "code": "invalidResourceId"
    }
  }
}
}
}

给我的第一印象是我为request.body设置了错误的JSON值,如何克服这个错误?

My first impression is that I am setting the request.body with a wrong value of JSON how to overcome this error?

推荐答案

您提供的ID(file.88e469b2d4c51142.88E469B2D4C51142!113)不是此API的有效ID.它看起来像是从LiveConnect API获得的,但与该新API不兼容.如果您使用新的api获取ID并将其与您的同一查询一起使用,那么它应该可以正常工作.

The id you provided (file.88e469b2d4c51142.88E469B2D4C51142!113) is not a valid id for this API. It looks suspiciously like one obtained from the LiveConnect API, and those aren't compatible with this new API. If you obtain the id using the new api and use that with your same query it should work.

这篇关于HTTP Post请求遇到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆