Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Body retorna vazio quando roda no cmd

C:\Users\Jessica\payfast>curl http://localhost:3000/pagamentos/pagamento -X POST -v -H "
Content-type: application/json" -d '{"forma_de_pagamento":"payfast","valor":10.9
8,"moeda":"BRL","descricao":"criando um pagamento"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> POST /pagamentos/pagamento HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.63.0
> Accept: */*
> Content-type: application/json
> Content-Length: 83
>
* upload completely sent off: 83 out of 83 bytes
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< Content-Security-Policy: default-src 'self'
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Content-Length: 1046
< Date:Thu, 11 Apr 2019 16:21:58 GMT
< Connection: keep-alive
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token ' in JSON at position 0<br>    
at JSON.parse (<anonymous>)<br>    at createStrictSyntaxError (C
:\Users\Jessica\payfast\node_modules\body-parser\lib\types\json.js:158:10)<br> &
nbsp;  at parse (C:\Users\Jessica\payfast\node_modules\body-parser\lib\type
s\json.js:83:15)<br>    at C:\Users\Jessica\payfast\node_modules\body-
parser\lib\read.js:121:18<br>    at invokeCallback (C:\Users\Jessica\p
ayfast\node_modules\raw-body\index.js:224:16)<br>    at done (C:\Users
\Jessica\payfast\node_modules\raw-body\index.js:213:7)<br>    at Incom
ingMessage.onEnd (C:\Users\Jessica\payfast\node_modules\raw-body\index.js:273:7)
<br>    at IncomingMessage.emit (events.js:182:13)<br>    at
 endReadableNT (_stream_readable.js:1094:12)<br>    at process._tickCa
llback (internal/process/next_tick.js:63:19)</pre>
</body>
</html>
* Connection #0 to host localhost left intact

já tentei colocando :

C:\Users\Jessica\node>curl http://localhost:3000/pagamentos/pagamento-X POST -v -H "Content-type: application/json" -d @pagamento.json
Warning: Couldn't read data from file "people.json", this makes an empty POST.
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> POST /pagamentos/pagamento HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.55.1
> Accept: */*
> Content-type: application/json
> Content-Length: 0
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/html; charset=utf-8
< Content-Length: 3
< ETag: W/"3-2eFyriMnGTsETXuIK8rfujgO4jI"
< Date: Thu, 11 Apr 2019 16:21:58 GMT
< Connection: keep-alive
<
OK!* Connection #0 to host localhost left intact

Alguém pode me dar uma luz ? estou fazendo no prompt de comando do windows

4 respostas

Oi Jessica tudo bem?

Poderia ,por gentileza, colocar a pasta do seu projeto no github para podermos analisar.

git clone https://araujojessica@bitbucket.org/araujojessica/alura-nodejs.git

Fiz pelo bitbucket André !

Obrigada

solução!

André consegui ver o erro ... na url quando uso o @ precisava coloca @files/people.json

Obrigada pela atenção.

Que bom que conseguiu Jessica!

Tava com dificuldades aqui pra achar o erro rsrsrs, tava até conversando com outros moderadores.

Bons estudos!!!