我正在开发一个模块,该模块要求我使用API将数据输入RightMove。但在此之前,它需要相互验证来验证数据馈线--它使用了一些证书和密钥。
我从RightMove收到了以下文件格式:
我还提供了一个由RightMove提供的密码用于这些(或其中的一个)文件。
现在,我必须使用这些文件来使用RightMove,但我不知道哪个文件可以完成什么任务。我用的是Axios和Node.js
有人能帮我形成一个axios调用来利用这些文件吗?
发布于 2020-04-28 10:29:28
所以我只使用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-15 15:45:06
因此,我看了一下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实例,这意味着您只需要为所有请求设置这些选项一次。
https://stackoverflow.com/questions/61227914
复制相似问题