curl Post Json
$ curl -i -X POST -H "'Content-type':'application/x-www-form-urlencoded', 'charset':'utf-8', 'Accept': 'text/plain'" -d 'json_data={"a":"aaa","b":"bbb","data":[{"c":"ccc","d":"ddd","keywords":[{"e": "eee", "f":"fff", "g":"ggg"}]}]}' url
返回信息:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=02565379F21852B33D0367FB7982FE1C; Path=/; HttpOnly
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 22 Oct 2013 10:48:24 GMT
这里想要post Json数据到接口上,需要设置好Header,也就是:'Content-type':'application/x-www-form-urlencoded', 'charset':'utf-8', 'Accept': 'text/plain'。
之前一直认为是设置好Content-Type=application/json即可,但是如果有中文就会遇到需要encode的地方了。