【发布时间】:2015-07-23 06:53:45
【问题描述】:
我正在为一个项目使用 TripIt.com API,但我完全不知道如何将此 CURL 命令转换为 Java。
$ curl -k -D /dev/tty --data-urlencode xml@/var/tmp/trip.xml --user <username>:<password> https://api.tripit.com/v1/create
HTTP/1.1 200 OK
Server: nginx/0.6.32
Date: Fri, 05 Dec 2008 22:12:35 GMT
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
我知道我必须使用URLConnection,但不知道如何设置其他值。比如用户名、密码、XML 文件的路径等等......
我该怎么做?
【问题讨论】:
-
我建议使用特定的库来缓解此类问题。 Apache HttpClient 有特定的结构和方法来解决您的问题hc.apache.org/httpcomponents-client-4.5.x/quickstart.html
标签: java curl httpurlconnection