Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

637
Views
Falta el error del agente de usuario en ReactJS fetch api

Estoy usando News API en ReactJS para obtener noticias usando fetch API.

FRAGMENTO DE CÓDIGO

 const url = `https://newsapi.org/v2/top-headlines?country=in&category=${this.props.category}&pageSize=${this.state.pageSize}&page=${this.state.page}`; let data = await fetch(url);

Pero cuando lo ejecuto en el host local, dio un error 400 diciendo:

 {status: 'error', code: 'userAgentMissing', message: 'Please set your User-Agent header to identify your application. Anonymous requests are not allowed.'}

Cuando busqué lo mismo en Stack Overflow, obtuve un enlace de un problema similar aquí:

Error de falta de agente de usuario al realizar una solicitud de obtención a una API

Luego agregué el encabezado User-Agent en el argumento de la API de búsqueda:

FRAGMENTO DE CÓDIGO

 headers = new Headers({ "X-Api-Key": this.apiKey, "User-Agent": navigator.userAgent }); const url = `https://newsapi.org/v2/top-headlines?country=in&category=${this.props.category}&pageSize=${this.state.pageSize}&page=${this.state.page}`; let data = await fetch(url, { headers: this.headers });

Pero aún muestra el mismo error:

 {status: 'error', code: 'userAgentMissing', message: 'Please set your User-Agent header to identify your application. Anonymous requests are not allowed.'}

Este error solicita "User-Agent" en el encabezado de la solicitud, ¡pero ya está allí! Cuando miré en la sección de red del navegador Chrome.

Captura de pantalla de la sección de red de Chrome

Entonces, ¿cuál es exactamente el problema? ¿Y cómo solucionar este problema?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!