Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda