如何在R中使用POST检索响应 [英] How to retrieve response by using POST in R

查看:116
本文介绍了如何在R中使用POST检索响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我希望输入"905/8 Ronayne St",并输出"12343197398".

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

我正在使用R并尝试过这种方法,但是没有用..

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

推荐答案

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

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

这篇关于如何在R中使用POST检索响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆