Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro API iChat com curl

Boa noite, iniciando a segunda aula do curso vi que tinha que baixar o ichat-api.jar, realizei o download porém não consegui realizar o método curl, pois toda vez que realizo a tentativa de realizar a requisição POST, é lançado uma exceção. Foi realizado a tentativa para acessar em linux e windows, abaixo encontrasse o comando utilizado e o erro gerado:

curl -X POST -H "Content-type: application/json" -d "{\"text\":\ "Olá aluno de Android!!!\",\"id\":123}" http://localhost:8080/polling


{"timestamp":1486177886992,"status":400,"error":"Bad Request","exception":"org.s
pringframework.http.converter.HttpMessageNotReadableException","message":"Could
not read document: Invalid UTF-8 middle byte 0x20\n at [Source: java.io.Pushback
InputStream@7cc06ae8; line: 1, column: 14]\n at [Source: java.io.PushbackInputSt
ream@7cc06ae8; line: 1, column: 9] (through reference chain: br.com.caelum.ichat
.model.Message[\"text\"]); nested exception is com.fasterxml.jackson.databind.Js
onMappingException: Invalid UTF-8 middle byte 0x20\n at [Source: java.io.Pushbac
kInputStream@7cc06ae8; line: 1, column: 14]\n at [Source: java.io.PushbackInputS
tream@7cc06ae8; line: 1, column: 9] (through reference chain: br.com.caelum.icha
t.model.Message[\"text\"])","path":"/polling"}
curl -X POST -H "Content-type: application/json" -d {"""text""":"""Olá aluno de Android!!!""","""id""":123} http://localhost:8080/polling


curl: (6) Could not resolve host: aluno
curl: (6) Could not resolve host: de
curl: (3) [globbing] unmatched close brace/bracket in column 21
{"timestamp":1486177935241,"status":400,"error":"Bad Request","exception":"org.s
pringframework.http.converter.HttpMessageNotReadableException","message":"Could
not read document: Unexpected end-of-input in VALUE_STRING\n at [Source: java.io
.PushbackInputStream@5c74f39; line: 1, column: 25]\n at [Source: java.io.Pushbac
kInputStream@5c74f39; line: 1, column: 9] (through reference chain: br.com.caelu
m.ichat.model.Message[\"text\"]); nested exception is com.fasterxml.jackson.data
bind.JsonMappingException: Unexpected end-of-input in VALUE_STRING\n at [Source:
 java.io.PushbackInputStream@5c74f39; line: 1, column: 25]\n at [Source: java.io
.PushbackInputStream@5c74f39; line: 1, column: 9] (through reference chain: br.c
om.caelum.ichat.model.Message[\"text\"])","path":"/polling"}
curl -X POST -H "Content-type: application/json" -d '{\"text\":\"Olá aluno de Android!!!\",\"id\":123}' http://localhost:8080/polling
curl: (6) Could not resolve host: aluno
curl: (6) Could not resolve host: de
curl: (3) [globbing] unmatched close brace/bracket in column 21

{"timestamp":1486178062824,"status":400,"error":"Bad Request","exception":"org.s
pringframework.http.converter.HttpMessageNotReadableException","message":"Could
not read document: Unexpected character (''' (code 39)): expected a valid value
(number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io
.PushbackInputStream@5b70906e; line: 1, column: 2]; nested exception is com.fast
erxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): exp
ected a valid value (number, String, array, object, 'true', 'false' or 'null')\n
 at [Source: java.io.PushbackInputStream@5b70906e; line: 1, column: 2]","path":"
/polling"}
1 resposta
solução!

Oi Raniere, vc está escrevendo alguma coisa errada no curl... Minha dica é instalar um plugin do chrome, chamado postman => https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop Faz os testes por lá e deixa o curl de lado.