Search code examples
rapipostweb-scrapinghttr

How to retrieve response by using POST in R


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


Solution

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