IT袋

当前位置:主页 > 经验教程 > 建站编程 >

curl命令怎么用

curl命令怎么用 curl常用命令及参数详解(8)

更新:2023-08-11 17:28:08 来源:IT袋 作者:马勇
导读:curl命令怎么用,curl -F file=@cooltext.txt -F yourname=Daniel -F filedescription=Cool text file with cool text inside http://www.post.com/postit.cgi 要在一篇文章中发送两个文件,您可以通过两种方式

curl命令怎么用

curl -F "file=@cooltext.txt" -F "yourname=Daniel"
  -F "filedescription=Cool text file with cool text inside"
  http://www.post.com/postit.cgi
要在一篇文章中发送两个文件,您可以通过两种方式进行:

使用单个字段名称在单个“字段”中发送多个文件:

curl -F "pictures=@dog.gif,cat.gif" $URL
发送具有两个字段名称的两个字段

curl -F "docpicture=@dog.gif" -F "catpicture=@cat.gif" $URL

@要在不解释前导or<或嵌入的情况下按字面意思发送字段值;type=,请使用--form-string代替-F。当值是从用户或其他不可预测的来源获得时,建议这样做。在这些情况下,使用-F而不是--form-string可能允许用户欺骗 curl 上传文件。

推荐人

HTTP 请求可以选择包含有关哪个地址将其引用到实际页面的信息。curl 允许您指定要在命令行上使用的引荐来源网址。欺骗或欺骗依赖可用信息或包含某些数据的愚蠢服务器或 CGI 脚本特别有用。

curl -e www.coolsite.com http://www.showme.com/

用户代理

An HTTP request has the option to include information about the browser that generated the request. Curl allows it to be specified on the command line. It is especially useful to fool or trick stupid servers or CGI scripts that only accept certain browsers.

Example:

curl -A 'Mozilla/3.0 (Win95; I)' http://www.nationsbank.com/
Other common strings:

Mozilla/3.0 (Win95; I) - Netscape Version 3 for Windows 95
Mozilla/3.04 (Win95; U) - Netscape Version 3 for Windows 95
Mozilla/2.02 (OS/2; U) - Netscape Version 2 for OS/2
Mozilla/4.04 [en] (X11; U; AIX 4.2; Nav) - Netscape for AIX
Mozilla/4.05 [en] (X11; U; Linux 2.0.32 i586) - Netscape for Linux
Note that Internet Explorer tries hard to be compatible in every way:

Mozilla/4.0 (compatible; MSIE 4.01; Windows 95) - MSIE for W95
Mozilla is not the only possible User-Agent name:

Konqueror/1.0 - KDE File Manager desktop client
Lynx/2.7.1 libwww-FM/2.14 - Lynx command line browser
Cookies
Cookies are generally used by web servers to keep state information at the client's side. The server sets cookies by sending a response line in the headers that looks like Set-Cookie: <data> where the data part then typically contains a set of NAME=VALUE pairs (separated by semicolons ; like NAME1=VALUE1; NAME2=VALUE2;). The server can also specify for what path the "cookie" should be used for (by specifying path=value), when the cookie should expire (expire=DATE), for what domain to use it (domain=NAME) and if it should be used on secure connections only (secure).

If you have received a page from a server that contains a header like:

Set-Cookie: sessionid=boo123; path="/foo";
it means the server wants that first pair passed on when we get anything in a path beginning with "/foo".

相关阅读