2

使用此请求通过 REST V2 API 扁平化自动提交 URL 时

POST https://api.flattr.com/rest/v2/flattr

{"url":"https://flattr.com/submit/auto?user_id=myuserid&url=myurl"}

我收到此错误,尽管 URL 在任何浏览器中都可以正常工作并重定向到现有事物。

{
  "error_description" : "The requested thing(s) could not be found",
  "error_uri" : "http:\/\/developers.flattr.net\/api",
  "error" : "not_found"
}

所以要么我做错了什么,要么错误信息是错误的,还是别的什么?

4

2 回答 2

2

您可能对 url 编码有问题。为此,您需要先对自动提交 URL 进行 URL 编码。

http://blog.flattr.net/2011/10/api-v2-beta-out-whats-changed/变成http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F

然后,如果要将其作为常规 POST 请求发送,则需要对整个自动提交 URL 进行 URL 编码。

http://flattr.com/submit/auto?url=http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F&user_id=flattr变成http%3A%2F%2Fflattr.com%2Fsubmit%2Fauto%3Furl%3Dhttp%253A%252F%252Fblog.flattr.net%252F2011%252F10%252Fapi-v2-beta-out-whats-changed%252F%26user_id%3Dflattr.

如果要使用 JSON 发送它,则不需要对 flattr 自动提交 URL 进行 URL 编码。相反,您确实喜欢下面的示例。

{"url":"http://flattr.com/submit/auto?url=http%3A%2F%2Fblog.flattr.net%2F2011%2F10%2Fapi-v2-beta-out-whats-changed%2F&user_id=flattr"}

这意味着如果您执行常规 POST 请求,并且如果您仅将数据作为 JSON URL 编码发送一次,则部分 URL 将被 URL 编码两次。当您使用 JSON 正文执行 POST 请求时,您需要将其设置Content-Typeapplication/json使其工作。

于 2012-01-23T11:00:26.663 回答
0

我忘记为请求设置 Content-type 标头。它需要说“应用程序/json”。

于 2012-01-24T10:32:55.463 回答