如何在 R 中使用 POST 检索响应

How to retrieve response by using POST in R

如果您访问 https://www.aucklandcouncil.govt.nz/property-rates-valuations/pages/find-property-rates-valuation.aspx,您将看到搜索框。

我要输入“905/8 Ronayne St”,输出“12343197398”。

我正在使用 R 并尝试过这样但没有成功..

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")

你能帮帮我吗?将不胜感激:)

由于发送方式的原因,只需要在R中提供正确的header即可。

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'])