Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 error at a specific URL #4372

Closed
JaeseokWoo opened this issue Jan 9, 2022 · 1 comment
Closed

403 error at a specific URL #4372

JaeseokWoo opened this issue Jan 9, 2022 · 1 comment

Comments

@JaeseokWoo
Copy link

Describe the bug

I used axios for HTML parsing in my project.
Axios receives a 403 response from a specific URL.
For example, https://www.coupang.com/

I found a solution by comparing node-fetch and axios.
The solution is to add Accept-Encoding to the header.

To Reproduce

const axios = require("axios");

const url= "https://www.coupang.com/";

axios.get(url).then((res) => {
  console.log('no Accept-Encoding status:', res.status);
  })
  .catch((error) => {
    console.error('no Accept-Encoding status:', error.response.status);
  });

const config = {
  headers: {
    'Accept-Encoding': 'gzip, deflate, br'
  }
};

axios.get(url, config).then((res) => {
  console.log('Accept-Encoding status:', res.status);
})
.catch((error) => {
  console.error('Accept-Encoding status:', error.response.status);
});

Expected behavior

If you make a request without Accept-Encoding, you will receive a 403 response.
However, if you request by adding Accept-Encoding, you will receive 200 responses.

Environment

  • Axios Version ^0.24.0
  • Adapter HTTP/HTTPS
  • Node.js Version v14.17.3
  • OS: windows10 x64

Additional context/Screenshots

axios result

JaeseokWoo added a commit to JaeseokWoo/axios that referenced this issue Jan 9, 2022
Accept-Encoding was added to solve the 403 response.
@momguide
Copy link

momguide commented Jun 3, 2022

Thanks,
save my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants