最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - add language to header using axios - Stack Overflow

programmeradmin1浏览0评论

I have been creating a web application using ReactJS and Symfony, I want to add a multi language functionality to my application. The problem is when I add locale to requests as a header parameter, I'm getting a Failed to load response data, also I see the message Provisional headers are shown

const instance = axios.create({
baseURL: 'myapp',
headers: {
    'Content-Type': 'application/ld+json',
    locale: 'en'
}});

when I remove the parameter locale it work correctly and the request passed to the API and the worning message "Provisional headers are shown" disappear from the browser.

how can I solve the problem ?. Thanks.

I have been creating a web application using ReactJS and Symfony, I want to add a multi language functionality to my application. The problem is when I add locale to requests as a header parameter, I'm getting a Failed to load response data, also I see the message Provisional headers are shown

const instance = axios.create({
baseURL: 'myapp.',
headers: {
    'Content-Type': 'application/ld+json',
    locale: 'en'
}});

when I remove the parameter locale it work correctly and the request passed to the API and the worning message "Provisional headers are shown" disappear from the browser.

how can I solve the problem ?. Thanks.

Share Improve this question edited Jan 3, 2021 at 22:19 Naruto Uzumaki asked Jan 3, 2021 at 21:56 Naruto UzumakiNaruto Uzumaki 3182 gold badges7 silver badges11 bronze badges 5
  • Are any other error messages shown? This seems like the sort of thing that would trigger a CORS related error message. – Quentin Commented Jan 3, 2021 at 22:00
  • 1 Why are you setting a header called local? That isn't even a word used for language related things (like locale) and there's a perfectly good, standard Accept-Language request header! – Quentin Commented Jan 3, 2021 at 22:00
  • I dont want to set Accept-Language, I want to add a new parameter locale to all requests. when I add it all request doesn't passed. then I see the message "Provisional headers are shown" in the browser (header section) – Naruto Uzumaki Commented Jan 3, 2021 at 22:13
  • Leaving aside that it's bizarre to use a made up header instead of a standard one: You need to address my first ment. – Quentin Commented Jan 3, 2021 at 22:24
  • @Quentin there aren't any other problem. – Naruto Uzumaki Commented Jan 3, 2021 at 22:31
Add a ment  | 

2 Answers 2

Reset to default 4

Do you mean you want to set the accept language?

headers: {
      "Accept-Language": "en-US,en;"
}

I added the locale to the list of parameters accepted in the allow_header section of the API and now it works.

allow_headers: ['Content-Type', 'Authorization', 'locale']
发布评论

评论列表(0)

  1. 暂无评论