【发布时间】:2021-06-14 10:57:00
【问题描述】:
我在 Python 中有以下请求。如何在R 的httr 包中重写这个?
我不确定的是如何在 R 中翻译 json 和 tuple 等效项。
import requests
cookies = {}
headers = {
'Host': 'mysejahtera.malaysia.gov.my',
'Accept': 'application/json',
'Connection': 'keep-alive',
'Content-Length': '77',
'Authorization': 'Basic N0ZFRkRCMTMtN0Q2MC00NEQxLUE5MTctM0',
'Content-Type': 'application/json',
'Accept-Language': 'en-MY;q=1, ms-MY;q=0.9',
'User-Agent': 'MySejahtera/1.0.36 (iPhone; iOS 14.6; Scale/2.00)',
}
params = (
('type', 'search'),
)
data = '[{"lat":3.003090,"lng":101.678300,"classification":"LOW_RISK_NS"}]'
response = requests.post('https://mysejahtera.malaysia.gov.my/register/api/nearby/hotspots', headers=headers, params=params, cookies=cookies, data=data)
response.json()
这是一个尝试。但仍然发出400 错误请求
POST("https://mysejahtera.malaysia.gov.my/register/api/nearby/hotspots?type=search",
body = list(lat = 3.003090, lng = 101.678300, classification = 'LOW_RISK_NS'),
add_headers(Host= 'mysejahtera.malaysia.gov.my',
Accept= 'application/json',
Connection= 'keep-alive',
`Content-Length`= '77',
Authorization= 'Basic N0ZFRkRCMTMtN0Q2MC00NEQxLUE5MTctM0',
`Content-Type`= 'application/json',
`Accept-Language`= 'en-MY;q=1, ms-MY;q=0.9',
`User-Agent`= 'MySejahtera/1.0.36 (iPhone; iOS 14.6; Scale/2.00)'), verbose())
【问题讨论】: