在 httr GET 请求中传递 odata $filter [英] passing odata $filter in httr GET request

查看:66
本文介绍了在 httr GET 请求中传递 odata $filter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望使用 R 的 httr 包中的 odata 传递 $filter 标准,但不断收到错误 400.请求格式错误".

looking to pass $filter criteria using odata in R's httr package, but keep getting an 'Error 400. The request is badly formed'.

我可以将 url/$filter 粘贴到我的浏览器中并获得结果,并且我也可以在没有 $filter 的情况下在 R 中获得结果.只是在 R 中使用 $filter 选项,我收到了错误:

I'm able to paste the url/$filter in my browser and obtain results ok, and am also to obtain results in R without the $filter. It's just using the $filter option in R that I'm getting the error:

library(httr)
url <- "https://api.prosper.com/api/ListingsHistorical?$filter=year(ListingCreationDate) eq 2014"
response <- GET(url, authenticate('user', 'pass')

以上,在 R 中,是抛出 400 响应的原因.在浏览器中工作正常.

Above, in R, is what's throwing the 400 response. In browser works fine.

推荐答案

想通了.在声明 url 变量时,我需要在空格中包含 %20.

Figured it out. I needed to include %20 for the spaces when declaring the url variable.

工作:

library(httr)
url <- "https://api.prosper.com/api/ListingsHistorical?$filter=year(ListingCreationDate)%20eq%202014"
response <- GET(url, authenticate('user', 'pass')

这篇关于在 httr GET 请求中传递 odata $filter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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