Блог пользователя emeralddd

Автор emeralddd, история, 2 недели назад, По-английски

I have recently tried API of Polygon. All things worked correctly until I found I couldn't update statements containing some special Vietnamese characters (eg: ê, ô, ...).

This is my code:

const { default: axios } = require('axios');
const { sha512 } = require('js-sha512');

const a = async () => {
    const key = "xxx";
    const secret = "yyy";

    const date = Math.floor(new Date().getTime() / 1000);
    const rand = 100000 + Math.floor(Math.random() * 900000);

    const apiSig = sha512(`$$${rand}/problem.saveStatement?apiKey=$$${key}&lang=english&legend=ê&problemId=351173&time=${date}#${secret}`);

    const req = await axios.post(`https://polygon.codeforces.com/api/problem.saveStatement?apiKey=${key}&lang=english&legend=${encodeURIComponent('ê')}&problemId=351173&time=${date}&apiSig=${rand}${apiSig}`);

    return req.data;
}

a();

Nodejs 20.11.1 Axios 1.6.8

After I had sent the request, I got the error message: "Incorrect signature". Everything worked normally when I removed all the special Vietnamese characters.

Anyone can help me with this issue, pls!

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится