0
1

More than 1 year has passed since last update.

axiosでPUTしたらPHPの$_POSTが空になる件

Posted at

PHPではPUTメソッドの時は標準入力からデータを取る。
PHP: PUT メソッドのサポート - Manual

いやどう考えても面倒くさい。

axios側で対応

POSTで送信してX-HTTP-Method-OverrideヘッダでPUTを指定すれば良いぞ。

axios v1.2.1
axios.interceptors.request.use((config) => {
  const method = config.method?.toLowerCase();

  if (method === 'put') {
    config.method = 'post';
    config.headers = { 
      ...config?.headers,
      'X-HTTP-Method-Override': 'PUT'
    };
  }

  return config;
});
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1