0

我正在开发一个模块,该模块需要我使用他们的 API 将数据输入 RightMove。但在此之前,它需要相互身份验证来验证数据馈送器——它使用一些证书和密钥。

我从 RightMove 收到了以下文件格式:

  • 文件.jks
  • 文件.p12
  • 文件.pem

我还有一个 RightMove 提供的密码短语,可用于这些(或其中一个)文件。

现在我必须使用这些文件来使用 RightMove 进行身份验证,但我不确定哪个文件能做什么。我正在将 Axios 与 Node.js 一起使用

有人可以帮我形成一个利用这些文件进行身份验证的 axios 调用吗?

4

2 回答 2

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. 文档提到他们有 JSON 或 XML 模式可供下载这里。您还可以查看示例响应。

因为您很可能会进行多次调用,所以我创建了一个 axios 实例,这意味着您只需为所有请求设置一次这些选项。

于 2020-04-15T15:45:06.053 回答
-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 })
于 2020-04-28T10:29:28.493 回答