JavaScript-How do I post a section of text with the Chinese JSON to the server with curl?

Source: Internet
Author: User
Tags what header
The CURL command says so.

curl -X POST http://localhost:3000/api/licenses/eee -d itemdata='{"nType":"1","nBaoYou":"0","szItemId":"536347062406","title":"秋冬新款女装韩版半高领毛 衣女加厚修身显瘦长袖套头针织衫打底衫","secondTitle":"","imgURL":"http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"限时秒杀价","fOldPrice":"108","fThirdPrice":"0","fCommissionPer":"10.5","fCommission":"2.08","nTgCount":"0","nSellCount":"37","fPingFen":"0","nPingjiaCount":"5","szTgURL":"","szWebTgURL":"","szBlogTgURL":"","shortUrl":"","szDesc":"","nick":"艾伦圣玛旗舰店","coupon":""}'

The server receives the following code: The last brackets do not match

{ itemdata: '\'{nType:1,nBaoYou:0,szItemId:536347062406,title:�ﶬ�¿�Ůװ����������ë ��Ů�Ӻ��������ݳ�����ͷ��֯��������,secondTitle:,imgURL:http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg,promotionTxt:��ʱ��ɱ��,fOldPrice:108,fThirdPrice:0,fCommissionPer:10.5,fCommission:2.08,nTgCount:0,nSellCount:37,fPingFen:0,nPingjiaCount:5,szTgURL:,szWebTgURL:,szBlogTgURL:,shortUrl:,szDesc:,nick:����ʥ���콢��,coupon:}\'' }

And if the JSON server is passed directly, it seems to wrap a layer of key=>value, and here is the Curl command.

curl -X POST http://localhost:3000/api/licenses/eee -d {"itemdata":{"nType":"1","nBaoYou":"0","szItemId":"536347062406","title":"秋冬新款女装韩版半高领毛 衣女加厚修身显瘦长袖套头针织衫打底衫","secondTitle":"","imgURL":"http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"限时秒杀价","fOldPrice":"108","fThirdPrice":"0","fCommissionPer":"10.5","fCommission":"2.08","nTgCount":"0","nSellCount":"37","fPingFen":"0","nPingjiaCount":"5","szTgURL":"","szWebTgURL":"","szBlogTgURL":"","shortUrl":"","szDesc":"","nick":"艾伦圣玛旗舰店","coupon":""}}

Here's the result.

{  "{itemdata:{nType:1,nBaoYou:0,szItemId:536347062406,title:锟斤冬锟铰匡拷女装锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷毛 锟斤拷女锟接猴拷锟斤拷锟斤拷锟斤拷锟捷筹拷锟斤拷锟斤拷头锟斤拷织锟斤拷锟斤拷锟斤拷锟斤拷,secondTitle:,imgURL:http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg,promotionTxt:锟斤拷时锟斤拷杀锟斤拷,fOldPrice:108,fThirdPrice:0,fCommissionPer:10.5,fCommission:2.08,nTgCount:0,nSellCount:37,fPingFen:0,nPingjiaCount:5,szTgURL:,szWebTgURL:,szBlogTgURL:,shortUrl:,szDesc:,nick:锟斤拷锟斤拷圣锟斤拷锟届舰锟斤拷,coupon:}}": ""}

Now it's two questions.
1 How should the first one pass the Chinese json in curl?
2 How to make the server parse the correct JSON, because the http.post with JS can be correctly accepted ....

Hope the great God gives guidance

Reply content:

The CURL command says so.

curl -X POST http://localhost:3000/api/licenses/eee -d itemdata='{"nType":"1","nBaoYou":"0","szItemId":"536347062406","title":"秋冬新款女装韩版半高领毛 衣女加厚修身显瘦长袖套头针织衫打底衫","secondTitle":"","imgURL":"http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"限时秒杀价","fOldPrice":"108","fThirdPrice":"0","fCommissionPer":"10.5","fCommission":"2.08","nTgCount":"0","nSellCount":"37","fPingFen":"0","nPingjiaCount":"5","szTgURL":"","szWebTgURL":"","szBlogTgURL":"","shortUrl":"","szDesc":"","nick":"艾伦圣玛旗舰店","coupon":""}'

The server receives the following code: The last brackets do not match

{ itemdata: '\'{nType:1,nBaoYou:0,szItemId:536347062406,title:�ﶬ�¿�Ůװ����������ë ��Ů�Ӻ��������ݳ�����ͷ��֯��������,secondTitle:,imgURL:http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg,promotionTxt:��ʱ��ɱ��,fOldPrice:108,fThirdPrice:0,fCommissionPer:10.5,fCommission:2.08,nTgCount:0,nSellCount:37,fPingFen:0,nPingjiaCount:5,szTgURL:,szWebTgURL:,szBlogTgURL:,shortUrl:,szDesc:,nick:����ʥ���콢��,coupon:}\'' }

And if the JSON server is passed directly, it seems to wrap a layer of key=>value, and here is the Curl command.

curl -X POST http://localhost:3000/api/licenses/eee -d {"itemdata":{"nType":"1","nBaoYou":"0","szItemId":"536347062406","title":"秋冬新款女装韩版半高领毛 衣女加厚修身显瘦长袖套头针织衫打底衫","secondTitle":"","imgURL":"http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg","promotionTxt":"限时秒杀价","fOldPrice":"108","fThirdPrice":"0","fCommissionPer":"10.5","fCommission":"2.08","nTgCount":"0","nSellCount":"37","fPingFen":"0","nPingjiaCount":"5","szTgURL":"","szWebTgURL":"","szBlogTgURL":"","shortUrl":"","szDesc":"","nick":"艾伦圣玛旗舰店","coupon":""}}

Here's the result.

{  "{itemdata:{nType:1,nBaoYou:0,szItemId:536347062406,title:锟斤冬锟铰匡拷女装锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷毛 锟斤拷女锟接猴拷锟斤拷锟斤拷锟斤拷锟捷筹拷锟斤拷锟斤拷头锟斤拷织锟斤拷锟斤拷锟斤拷锟斤拷,secondTitle:,imgURL:http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg,promotionTxt:锟斤拷时锟斤拷杀锟斤拷,fOldPrice:108,fThirdPrice:0,fCommissionPer:10.5,fCommission:2.08,nTgCount:0,nSellCount:37,fPingFen:0,nPingjiaCount:5,szTgURL:,szWebTgURL:,szBlogTgURL:,shortUrl:,szDesc:,nick:锟斤拷锟斤拷圣锟斤拷锟届舰锟斤拷,coupon:}}": ""}

Now it's two questions.
1 How should the first one pass the Chinese json in curl?
2 How to make the server parse the correct JSON, because the http.post with JS can be correctly accepted ....

Hope the great God gives guidance

You want to do a test, go download a postman.

Try saving the data you want POST in a json file, such as Itemdata.json:

{    "nType":"1",    "nBaoYou":"0",    "szItemId":"536347062406",    "title":"秋冬新款女装韩版半高领毛 衣女加厚修身显瘦长袖套头针织衫打底衫",    "secondTitle":"",    "imgURL":"http://img4.tbcdn.cn/tfscom/i1/TB1OniJLXXXXXXzXpXXXXXXXXXX_!!0-item_pic.jpg",    "promotionTxt":"限时秒杀价",    "fOldPrice":"108",    "fThirdPrice":"0",    "fCommissionPer":"10.5",    "fCommission":"2.08",    "nTgCount":"0",    "nSellCount":"37",    "fPingFen":"0",    "nPingjiaCount":"5",    "szTgURL":"",    "szWebTgURL":"",    "szBlogTgURL":"",    "shortUrl":"",    "szDesc":"",    "nick":"艾伦圣玛旗舰店",    "coupon":""}

In the Headers , set Content-Type to application/json then execute the following command:

curl http://localhost:3000/api/licenses/eee -H "Content-Type: application/json" -X POST --data @itemdata.json

Data can be encoded after transmission.

Use Firefox to see what people preach, with what header, sighting fill up, I do so

Make sure the shell and PHP code are the same

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.