I've been trying to use httr package in R to send a POST request
The website which I'm trying to send a POST request states to do the following:
POST /newwebservices/locationverifier.asmx/findLocation2 HTTP/1.1
Host: citizenatlas.dc.gov
Content-Type: application/x-www-form-urlencoded
Content-Length: length
str=string&f=string
where str takes an address in Washington DC such as "701 FARADAY PL NE, WASHINGTON, DC 20017" and f takes the format requested in this case I want "json"
I tried :
url = "/newwebservices/locationverifier.asmx HTTP/1.1"
body = list(
"Host" = "citizenatlas.dc.gov",
"Content-Type" = "application/x-www-form-urlencoded",
"Content-Length" = length,
"str"="3513 S St NW",
"f"="json"
)
httr::POST(url,body, verbose)
I also tried Get This is what they state to put in
GET /newwebservices/locationverifier.asmx/findLocation2? str=string&f=string HTTP/1.1
Host: citizenatlas.dc.gov
or
GET("http://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation2?str=3513 S St NW&f=json")
but nothing is working. By the way, I had no problem making the request using Mathematica.
I will appreciate any help. Thank You in Advance.
答案 0 :(得分:1)
这里发生了一些不同的事情。下面的作品:
url <- "http://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation2"
body <- list(str = "3513 S St NW", f = "json")
httr::POST(url, body = body, encode = "json")
一些区别:
httr::POST
文档)body
和encode
之所以命名,是因为它们不在文档中的位置上,因此位置参数匹配不起作用