API中curl命令行遇到的问题总结

Q1:curl命令行中返回结果有中文,在windows cmd中出现乱码。

      本以为是本身utf-8编码没有设置,但是设置之后发现问题依然存在,于是乎转向怀疑windows cmd本身的问题,查阅资料得知windows环境下cmd默认编码是GBK,若要改成utf-8显示需要手动设置,设置方法见下:http://jingyan.baidu.com/article/e75aca85440f01142edac636.html

Q2:curl -d 和curl -f不可以同时使用,那么很多朋友就会问表单post提交的数据既有用户数据,又有上传的文件,那该怎么办?

      首先不能同时使用的原因是:(来源于curl官网帮助http://curl.haxx.se/docs/manpage.html)

-d, --data <data>

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using thecontent-type application/x-www-form-urlencoded. Compare to -F, --form.

-F, --form <name=content>

(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-dataaccording to RFC 2388

      因为两种编码格式不同,注定不能在curl的一条命令行里共存。

      在这里同时传递两种数据我们统一使用-f。

curl -F uploadFiles=@D:\ibotest\test.ppt -F "DATA={\"sender\":\"aaaa\",\"receiver\":\"bbbb\"}" http://localhost:8080/WebTest/webtest因为两种编码格式不同,注定不能在curl的一条命令行里共存
      在服务器端接收的时候java后台代码如下(这里使用了SmartUpload组件)

SmartUpload su=new SmartUpload();
su.initialize(getServletConfig(), request, response);
com.jspsmart.upload.Request req = su.getRequest();
su.upload();
revdata=req.getParameter("DATA");
System.out.println(revdata);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值