Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
Issue with using the axios post method with a couchdb local database

I am trying to use Axios to perform a post to a local couchdb database.

const options = {
            headers: {
                'Content-type': 'multipart/form-data',
                Referer: "http://localhost:5984",
                Accept: "application/json"
            }
        }
try{
            const response = await axios.get("http://Username:Password@localhost:5984/users/" + user.Name + "/")
            rev = response.data._rev
            console.log("Fresh _rev acquired.\n\n")
        }catch{
            console.log("An error occured")
        }
        try{ 
            var response = await axios.post('http://Username:Password@localhost:5984/users/' + user.Name + '/?_rev="' + rev + '"', user, options)
            console.log("posted\n\n")
        }catch(error){
            console.log("post failed\n", error)
        }

This produces an error message. "Request failed with status code 500" The data line of the error message is: data: { error: 'case_clause', reason: 'undefined', ref: 2200284843 } After researching the problem I believe the error is caused by axios using multipart/form-data rather than application/json, but when I change that I get errors stating that the content type must be multipart/form-data. I have found a work around for using the post method by using a get, then deleting the document in the database and finally using a put to make a new document. It is just really bothering me that after a few days of trying to understand the issues I been having with this post method that I am still empty handed. If you have anything that may help, I would greatly appreciate it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solved the error 500 by changing the Content-type back to application/json in the header

headers: {
    'Content-type': 'application/json',
    Referer: "http://localhost:5984",
    Accept: "application/json"
} 

For this change couchdb returned an error 415. After a bit more digging, and some trial and error I removed the {docid} and revision number from the URL and included them in the data portion of the request.

try{ 
    var response = await axios.post('http://Username:Password@localhost:5984/twitchusers/' /*+ user.Name + '/'?_rev="' + rev + '"'*/, {_id: user.Name, _rev: rev, user}, options)
    console.log("posted\n\n")
}catch(error){
    console.log("post failed\n", error)
}

This change resulted in no error.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda