Closed xkungfu closed 3 years ago
curl http://localhost:8000/todos -d "task=something new" -X POST -v
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1:8000...
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST /todos HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.75.0
> Accept: */*
> Content-Length: 18
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Content-Length: 673
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
< Keep-Alive: 5
<
<!DOCTYPE html><html lang=en><meta charset=UTF-8><title>⚠️ 400 — Bad Request</title>
<style>
html { font-family: sans-serif }
h2 { color: #888; }
.tb-wrapper p { margin: 0 }
.frame-border { margin: 1rem }
.frame-line > * { padding: 0.3rem 0.6rem }
.frame-line { margin-bottom: 0.3rem }
.frame-code { font-size: 16px; padding-left: 4ch }
.tb-wrapper { border: 1px solid #eee }
.tb-header { background: #eee; padding: 0.3rem; font-weight: bold }
.frame-descriptor { background: #e2eafb; font-size: 14px }
</style>
<h1>⚠️ 400 — Bad Request</h1><p>Failed when parsing body as json
* Connection #0 to host localhost left intact
curl http://localhost:8000/todos -d "{\"task\": \"somethin new\"}" -v
* Trying ::1:8000...
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST /todos HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.75.0
> Accept: */*
> Content-Length: 24
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Content-type: application/json
< Content-Length: 20
< Connection: keep-alive
< Keep-Alive: 5
<
{
"task": "s"
}
* Connection #0 to host localhost left intact
finally worked. but what is "s"? why "something new" was changed to "s"?
parser.add_argument('task', location='json')
you can try it ,if not set location,code will update values form ('json', 'form', 'args', 'files'),finally the result is "s"
thanks.
server run on port 8000, not 5000.