我正在开发一个模块,该模块需要我使用其API将数据输入RightMove。但在此之前,它需要相互身份验证才能验证数据馈送器-该数据馈送器使用一些证书和密钥。
我从RightMove收到以下文件格式:
RightMove还提供了一个密码短语,可用于这些(或其中一个)文件。
现在,我必须使用这些文件对RightMove进行身份验证,但是我不确定哪个文件可以做什么。我在Node.js中使用Axios
有人可以帮我形成一个将这些文件用于auth的axios呼叫吗?
答案 0 :(得分:0)
https://media.rightmove.co.uk/ps/pdf/guides/adf/Rightmove_Real_Time_Datafeed_Specification.pdf
因此,我看了RightMove API的文档,并在第5页上说,它们根据开发环境为您提供全部三个文件。
因此,我们将使用.pem
文件。
const https = require('https')
const fs = require('fs')
const axios = require('axios')
const key = fs.readFileSync('./key.pem')
const ca = fs.readFileSync('./ca.crt')
const url = 'https://adfapi.rightmove.co.uk/'
const httpsAgent = new https.Agent({
rejectUnauthorized: true, // Set to false if you dont have the CA
key,
ca,
passphrase: 'YYY', // Would recommend storing as secret
keepAlive: false,
})
const axiosInstance = axios.create({ headers: { 'User-Agent': 'rightmove-datafeed/1.0' }, httpsAgent })
axiosInstance.get(url, { httpsAgent })
我注意到文档中指出,RightMove使用的某些API需要设置自定义User-Agent
。该文档提到它们具有可下载的here JSON或XML模式。您还可以查看示例响应。
由于您很可能要拨打多个电话,而我已经创建了axios实例,因此这意味着您只需为所有请求设置一次这些选项。
答案 1 :(得分:-1)
因此,我仅使用p12文件和密码短语解决了该问题。不需要JKS文件和PEM文件。
const httpsAgent = new https.Agent({
pfx: fs.readFileSync('/path/to/p12/file'),
passphrase: '<your-passphrase>',
})
await axios.post(url, data, { headers, httpsAgent })