如何将curl命令转换为axios

问题描述 投票:0回答:1

我正在寻找将curl命令转换为axios post。 我不知道curl到axios命令的映射。 卷曲脚本

$urlConn = curl_init();
curl_setopt($urlConn, CURLOPT_URL, 'https://www.test.com);  
curl_setopt($urlConn, CURLOPT_HEADER, false); 
curl_setopt($urlConn, CURLOPT_POST, true);
curl_setopt($urlConn, CURLOPT_POSTFIELDS, "some string");
curl_setopt($urlConn, CURLOPT_FRESH_CONNECT, true);
curl_setopt($urlConn, CURLOPT_FOLLOWLOCATION, false); 
curl_setopt($urlConn, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($urlConn, CURLOPT_RETURNTRANSFER, true);
$returned_info = curl_exec($urlConn);
curl_close($urlConn);

如有任何帮助,我们将不胜感激

curl axios
1个回答
0
投票

需要停止axios通过JSON发送请求,使用application/x-www-form-urlencoded。对于有效负载

const data = {:
title: 'some data'
}
const rs = await axios.post<string>(url, data, {
      headers: { 'content-type': 'application/x-www-form-urlencoded' },
    });
    const result = rs.data;
© www.soinside.com 2019 - 2024. All rights reserved.