1

I'm using Axios and React in my frontend app. When I'm trying to send POST request over HTTPS with Axios (xhr, fetch) and faced with the strange issue - my POST request turns into GET in Edge dev tools.

Here is my request:

const response = await axios.post(
        config.local + "/api/login/credentials",
        {
          login,
          password
        }
      ); 

Then I tried to dig dipper - created a simple HTTPS server and tried to send POST request from the client.

const https = require('https');
const fs = require('fs');

const options = {
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt')
};

const PORT = 8188;

function handleRequest(req, res){
    console.log(req.method);
}


const server = https.createServer(options, handleRequest);

server.listen(PORT, function(){
    console.log("Server listening on: https://localhost:" + PORT);
});

And then, as I understand it, that request does not reach the server.

Here are some links:

Issue link 1

Issue link 2

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

0

Is there any error in console? You could use Fiddler to trace the network traffic and see the details. Also mentioned in the first link you provided, you could also try the two solutions in your GitHub link:

Solution 1:

My issue is caused by HTTPS; the backend is requiring HTTPS while I send an HTTP post from front side. Now I fixed by changing both to HTTPS.

Or Solution 2:

I solved it by passing the data in a different format using the "URLSearchParams " class. I had the same problem with: Microsoft Edge 44.18362.267.0 Microsoft EdgeHTML 18.18362 Windows 10

I think the problem is that Edge only supports certain data types in post requests. If you want to use the content-type 'application/x-www-form-urlencoded' then use URLSearchParams to make it work in Edge and other browsers like Firefox and Chrome. Passing a querystring seems not to work in Edge even if it does in other browsers.

Modifying the original post source code, the result would be:

import Axios from 'axios'
import Promise from 'es6-promise'
Promise.polyfill()
const URL= 'http://192.168.0.112/account/login/username'

// Use URLSearchParams instead:
const dataParams = new URLSearchParams()
dataParams.append('username', 'admin')
dataParams.append('password', 'admin')

Axios.post(URL, dataParams, {
  // if you still have problems try more specific options like:
  // withCredentials: true,
  // crossdomain: true,
  // ...
})
.then(res=>{
    console.log(res)
    }
)
.catch(error=>{
    console.log(error)
    }
)

Aside from that, the issue in your question is usually caused by CORS. If you use CORS and request an untrusted origin, then Microsoft Edge will only send the GET request and lead to the failure of other requests. You could also refer to this thread to understand why CORS requests fail in Microsoft Edge but work in other browsers. Microsoft Edge also uses Enhanced Protected Mode, the outcome is that: if the site is trusted, it will make two requests, OPTIONS and GET, but if it's not trusted, it only makes the GET request which causes it to fail.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
0

In my case problem was caused by a self-sign certificate. As soon as I started using normal certificate everything began to work.