我正在嘗試對一些 php 代碼進行逆向工程,然后在 JS 中運行它。php代碼如下:$fields_string = ''; //url-ify the data for the POST foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //decode result; $data = json_decode($result, TRUE); //close connection curl_close($ch); return $data;我在 JS 中使用 axios,目前正在嘗試以下操作:const response: any = await axios.post(base_url, 'key1=value1&key2=value2', { headers: { 'Content-Type': "multipart/form-data" } });但我似乎遇到了問題,因為服務器無法正確解析正文。我想知道是否有人對它應該是什么樣子有任何提示?
如何將此 PHP curl 命令轉(zhuǎn)換為 JS
胡子哥哥
2022-06-16 10:25:50