How to retrieve response by using POST in R

て烟熏妆下的殇ゞ 提交于 2019-12-11 06:17:39

问题


If you visit https://www.aucklandcouncil.govt.nz/property-rates-valuations/pages/find-property-rates-valuation.aspx then you will see search box.

I want '905/8 Ronayne St' to be input, and '12343197398' to be output.

I am using R and tried like this but didn't work..

post <- POST("https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses", 
             body = list('ResultCount' = "10", 'SearchText' = "905/8 Ronayne St", 'RateKeyRequired' = "false"))

content(post, "text")

Can you please help me? That would be much appreciated :)


回答1:


Just need to provide the right header in R due to way sending.

R:

library(httr)

headers = c('Content-Type' = 'application/json; charset=UTF-8')
data = '{"ResultCount":"10","SearchText":"905/8 Ronayne St","RateKeyRequired":"false"}'
r <- httr::POST(url = 'https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses', httr::add_headers(.headers=headers), body = data)

print(content(r)[[1]]$ACRateAccountKey)

Py:

import requests

data = {"ResultCount":"10","SearchText":"905/8 Ronayne St","RateKeyRequired":"false"}    
r = requests.post('https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses', json=data).json()
print(r[0]['ACRateAccountKey'])


来源:https://stackoverflow.com/questions/58655930/how-to-retrieve-response-by-using-post-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!