英文:
R httr POST request for IPaC Location API
问题
I'm attempting to run the example request for the IPaC location API from: https://ipac.ecosphere.fws.gov/location/api
What I have below returns status 406:
library(httr)
library(jsonlite)
url <- 'https://ipacb.ecosphere.fws.gov/location/api/resources/'
body <- '{
"location.footprint": {
"coordinates": [[[[-95.1306152,30.4486737],[-93.6584473,29.4061051],
[-94.6691895,28.5314486],[-96.5368652,29.9834867],
[-95.1306152,30.4486737]]]],
"type":"Polygon"
},
"timeout": 2,
"apiVersion": "1.0.0",
"includeOtherFwsResources": true,
"includeCrithabGeometry": false
}'
r <- httr::POST(url, body = body, encode = "json")
# r <- httr::POST(url, content_type_json(), body = body)
# r <- httr::POST(url, body = body)
# r <- httr::POST(url, body = body, encode = "raw")
# r <- httr::POST(url, content_type_json(), body = body, encode = "raw")
str(content(r, "parsed"))
$ timestamp: num 1.68e+12
$ status : int 406
$ error : chr "Not Acceptable"
$ message : chr "A location was not specified. Locations can be sent as JSON in the location.footprint parameter or as WKT as th"| __truncated__
$ path : chr "/location/api/resources/"
I've adjusted the formatting for the location.footprint
as well as trying different permutations of httr::POST
(commented out in code above) but I'm not understanding how to translate the location.footprint
in my body to a format httr will accept. The example request I'm running works fine and returns 200 in Postman.
英文:
I'm attempting to run the example request for the IPaC location API from: https://ipac.ecosphere.fws.gov/location/api
What I have below returns status 406:
library(httr)
library(jsonlite)
url <- 'https://ipacb.ecosphere.fws.gov/location/api/resources/'
body <- '{
"location.footprint": {
\"coordinates\": [[[[-95.1306152,30.4486737],[-93.6584473,29.4061051],
[-94.6691895,28.5314486],[-96.5368652,29.9834867],
[-95.1306152,30.4486737]]]],
\"type\":\"Polygon\"
},
"timeout": 2,
"apiVersion": "1.0.0",
"includeOtherFwsResources": true,
"includeCrithabGeometry": false
}'
r <- httr::POST(url, body = body, encode = "json")
# r <- httr::POST(url, content_type_json(), body = body)
# r <- httr::POST(url, body = body)
# r <- httr::POST(url, body = body, encode = "raw")
# r <- httr::POST(url, content_type_json(), body = body, encode = "raw")
str(content(r, "parsed"))
List of 5
$ timestamp: num 1.68e+12
$ status : int 406
$ error : chr "Not Acceptable"
$ message : chr "A location was not specified. Locations can be sent as JSON in the location.footprint parameter or as WKT as th"| __truncated__
$ path : chr "/location/api/resources/"
I've adjusted the formatting for the location.footprint
as well as trying different permutations of httr::POST
(commented out in code above) but I'm not understanding how to translate the location.footprint
in my body to a format httr will accept. The example request I'm running works fine and returns 200 in Postman.
答案1
得分: 0
以下是翻译好的部分:
"Turns out the solution was pretty straightforward with a WKT parameter:" 译为 "原来解决方案相当简单,只需使用WKT参数:"
"url = 'https://ipacb.ecosphere.fws.gov/location/api/resources'" 译为 "url = 'https://ipacb.ecosphere.fws.gov/location/api/resources'"
"body <- '{\n "projectLocationWKT": "Polygon((-95.1306152 30.4486737,-93.6584473 29.4061051,-94.6691895 28.5314486,-96.5368652 29.9834867,-95.1306152 30.4486737))",\n "timeout": 2,\n "apiVersion": "1.0.0",\n "includeOtherFwsResources": true,\n "includeCrithabGeometry": false\n}'" 译为 "body <- '{\n "projectLocationWKT": "Polygon((-95.1306152 30.4486737,-93.6584473 29.4061051,-94.6691895 28.5314486,-96.5368652 29.9834867,-95.1306152 30.4486737))",\n "timeout": 2,\n "apiVersion": "1.0.0",\n "includeOtherFwsResources": true,\n "includeCrithabGeometry": false\n}'"
"r <- httr::POST(url, content_type_json(), body = body, encode = "raw")" 译为 "r <- httr::POST(url, content_type_json(), body = body, encode = "raw")"
"str(content(r, "parsed"))" 译为 "str(content(r, "parsed"))"
英文:
Turns out the solution was pretty straightforward with a WKT parameter:
url = 'https://ipacb.ecosphere.fws.gov/location/api/resources'
body <- '{
"projectLocationWKT": "Polygon((-95.1306152 30.4486737,-93.6584473 29.4061051,-94.6691895 28.5314486,-96.5368652 29.9834867,-95.1306152 30.4486737))",
"timeout": 2,
"apiVersion": "1.0.0",
"includeOtherFwsResources": true,
"includeCrithabGeometry": false
}'
r <- httr::POST(url, content_type_json(), body = body, encode = "raw")
str(content(r, "parsed"))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论