Linux 基础命令-CURL 表单上传文件

时间:2021-08-20 05:24:22

CURL

-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-
data according to RFC 2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get
the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a
file upload, while the < makes a text field and just get the contents for that text field from a file.

Example, to send your password file to the server, where 'password' is the name of the form-field to which /etc/passwd will be the input:

curl -F password=@/etc/passwd www.mypasswords.com

To read content from stdin instead of a file, use - as the filename. This goes for both @ and < constructs.

You can also tell curl what Content-Type to use by using 'type=', in a manner similar to:

curl -F "web=@index.html;type=text/html" url.com

or

curl -F "name=daniel;type=text/foo" url.com

You can also explicitly change the name field of a file upload part by setting filename=, like this:

curl -F "file=@localfile;filename=nameinpost" url.com

If filename/path contains ',' or ';', it must be quoted by double-quotes like:

curl -F "file=@\"localfile\";filename=\"nameinpost\"" url.com

or

curl -F 'file=@"localfile";filename="nameinpost"' url.com

Note that if a filename/path is quoted by double-quotes, any double-quote or backslash within the filename must be escaped by backslash.

See further examples and details in the MANUAL.

This option can be used multiple times.

(1)文件上传,Html 表单上传方式:
<form name="form1" method="post" enctype="multipart/form-data" action="http://www.a.com/file">
<div>
<label for="caption">AppId:</label>
<input id="AppId" onblur="javascript:updateAction();" type="text" value="cfttest"/>
</div>
<div>
<label for="image1">上传文件:</label>
<input name="filedata" type="file" />
</div>
<div>
<label for="image1">上传类型:</label>
<select id="uptype" name="uptype">
<option value="0">唯一</option>
<option value="1">覆盖</option>
</select>
</div>
<div>
<input type="submit" name="upload" value="上传" />
</div>
</form>

(2).curl --form upload=@a41.zip --form uptype=1 http://www.a.com/file

(3).curl -F "file=@a41.txt;filename=testaaabcd.txt" http://www.a.com/file

上传文件,文件名称:testaaabcd.txt

Post提交数据

 curl -d "b=20&t=b7693b96e99" http://api.web.com/Api/getList

Linux 基础命令-CURL 表单上传文件的更多相关文章

  1. django 基于form表单上传文件和基于ajax上传文件

    一.基于form表单上传文件 1.html里是有一个input type="file" 和 ‘submit’的标签 2.vies.py def fileupload(request ...

  2. java模拟表单上传文件,java通过模拟post方式提交表单实现图片上传功能实例

    java模拟表单上传文件,java通过模拟post方式提交表单实现图片上传功能实例HttpClient 测试类,提供get post方法实例 package com.zdz.httpclient; i ...

  3. Express下使用formidable实现POST表单上传文件并保存

    Express下使用formidable实现POST表单上传文件并保存 在上一篇文章中使用formidable实现了上传文件,但没将它保存下来. 一开始,我也以为是只得到了文件的相关信息,需要用fs. ...

  4. 巨蟒python全栈开发django11&colon;ajax&amp&semi;&amp&semi;form表单上传文件contentType

    回顾: 什么是异步? 可以开出一个线程,我发出请求,不用等待返回,可以做其他事情. 什么是同步? 同步就是,我发送出了一个请求,需要等待返回给我信息,我才可以操作其他事情. 局部刷新是什么? 通过jq ...

  5. vue form表单上传文件

    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js">< ...

  6. 使用form表单上传文件

    在使用form表单上传文件时候,input[type='file']是必然会用的,其中有一些小坑需要避免. 1.form的 enctype="multipart/form-data&quot ...

  7. libcurl提交表单上传文件

    不多说了,curl的http上传文件代码示例,有需要的可以参考. int http_post_file(const char *url, const char *user, const char *p ...

  8. 使用CURL模拟表单上传文件

    //以下代码适合PHP7.x PHP5.6$file = new CURLFile('./127.zip','application/octet-stream');$file->setMimeT ...

  9. 一个ajax实现表单上传文件的神器 formdata

    通过传统的form表单提交的方式上传文件: $.ajax({ url : "http://localhost:8080/STS/rest/user", type : "P ...

随机推荐

  1. 【Maven】解决缺少Jar包问题

    解决办法:进入项目的根目录(即 pom.xml文件所在的目录)执行:mvn dependency:copy-dependencies完成后进入eclipse,发现项目不再报错前提条件:1,安装了mav ...

  2. ci查询数据库

    public function getUsers() { $this->load->database();//载入数据库 $users = $this->db->get(&qu ...

  3. STM32的bulk双缓冲传输速度的讨论,硬件的坑永远填不完

    详情:http://bbs.21ic.com/forum.php?mod=viewthread&tid=109584   USB 1.0的最高12Mbps. USB 2.0的高速模式480Mb ...

  4. Enable test automation in Testlink

    Enabling Test Automation in Testlink   Step 1: Change config settings in testlink config file Edit c ...

  5. IMX51&plus;WINCE6&period;0平台缩写意义

    1.以EPIT为例 EPIT(Enhanced Periodic Interrupt Timer)为增强型周期中断定时器,其中有CR控制寄存器,要设置CR寄存器的SWR位,代码如下: // Asser ...

  6. UVa 10945 - Mother bear

    题目大意:给一个字符串,判断是否回文(忽略大小写,忽略非字母字符). #include <cstdio> #include <cctype> #include <cstr ...

  7. JS基础属性跟运算

    小编这周学了JS函数基础知识跟运算!!下面就迫不及待跟大家分享一下 [switch case的结构写法] 结构写法:(略) 2注意事项: ①switch结构()中的表达式.可以使用各种js支持的数据类 ...

  8. Cisco动态路由配置

    前言: 学完静态路由配置,该学动态路由.所以 学习完后来做终结. 准备: PC:192.168.1.10 R1:fa0/0 192.168.1.1 fa0/1 1.1.12.1 R2: fa0/0 1 ...

  9. java项目部署常用linux命令

    1.显示当前所有java进程pid的命令:jps2.查找文件或文件夹目录查找目录:find /(查找范围) -name '查找关键字' -type d查找文件:find /(查找范围) -name 查 ...

  10. 20190226&lowbar;xlVba提取查新标题和关键词

    Sub MainProc() Dim Sht As Worksheet Dim Wb As Workbook Set Wb = Application.ThisWorkbook Set Sht = W ...