html tool

显示标签为“curl”的博文。显示所有博文
显示标签为“curl”的博文。显示所有博文

2023年7月18日星期二

转:curl post文件内容

方法一:

 参考:https://www.jianshu.com/p/84d354a8de2c

问题

当使用curl命令时,如果你的请求体过长,curl工具会报argument list too long,那怎么解决呢?

解决方案

利用管道技术,让curl从管道里面读取参数

  1. 将请求体json保存到文本文件中,这里比如为search.txt
  2. 编写curl命令,通过管道读取数据,-d @-,示例如下:cat s.txt | curl  -X POST http://localhost:9200/index-1-2020.11.05/_search -H 'Content-Type:applicatin/json' -d @- > result.txt
  1. 说明:
    cat s.txt:通过管道,将cat的参数输入管道
    curl -u admin:admin: 这里假设你使用的认证为admin:admin
    -d @- : 这里-d指明请求体,@-代表从管道里面获取数据
    > result.txt:将请求结果写入result.txt文件

方法二:

参考:https://stackoverflow.com/questions/54090784/curl-argument-list-too-long
curl -X POST -d @filename.txt https://website.com/path

2023年3月29日星期三

curl: (35) SSL received a record that exceeded the maximum permissible length

 问题:curl访问提示“curl: (35) SSL received a record that exceeded the maximum permissible length”

解决:https本身有问题,改成http就ok了

2023年3月16日星期四

转curl在windows上运行提示msvcr100.dll丢失的解决方法

curl 在windows上运行 提示 msvcr100.dll丢失的解决方法

1、32位系统,则复制到C:\WINDOWS\system32目录下。 2、64位系统,则复制到C:\WINDOWS\system32目录下。 2、然后打开“开始-运行-输入regsvr32 msvcr100.dll”,回车即可解决错误提示

2023年3月1日星期三

转:curl响应返回为乱码

 参考:https://blog.csdn.net/benben0729/article/details/80882553

1.是用curl抓取的数据是用类似gzip压缩后的数据导致的乱码。
乱码:curl www.1ting.com |more
乱码:curl -H "Accept-Encoding: gzip"www.1ting.com | more
不乱码:curl -H "Accept-Encoding: gzip"www.1ting.com | gunzip | more

不乱码:curl www.1616.net |more
乱码:curl -H "Accept-Encoding: gzip"www.1616.net | more
不乱码:curl -H "Accept-Encoding: gzip"www.1616.net | gunzip | more

下面的a,b解释的是www.1ting.com,c,d解释是的www.1616.net
a.某个url,如果用不加任何选项的curl命令抓取后乱码,在curl后面加上Accept-Encoding:gzip,后面不加gunzip,则抓取的数据会乱码。
b.某个url,如果用不加任何选项的curl命令抓取后乱码,在curl后面加上Accept-Encoding:gzip,后面加上gunzip,则抓取的数据不会乱码。

c.某个url,如果用不加任何选项的curl命令抓取后不乱码,在curl后面加上Accept-Encoding:gzip,后面不加gunzip,则抓取的数据会乱码。
d.某个url,如果用不加任何选项的curl命令抓取后不乱码,在curl后面加上Accept-Encoding:gzip,后面加上gunzip,则抓取的数据不会乱码。

小总:
也就是说在curl后面加上Accept-Encoding:gzip,再用gunzip解压缩,则基本上可以保存数据不乱码

转:curl POST 上传文件

 参考:https://blog.csdn.net/FungLeo/article/details/80703365


用 -F "file=@__FILE_PATH__" 的请示,传输文件即可。命令如下:


curl localhost:8000/api/v1/upimg -F "file=@/Users/fungleo/Downloads/401.png" -H "token: 222" -v

2022年10月20日星期四

curl(3)[globbing] error: bad range specification after pos

 转:https://stackoverflow.com/questions/8333920/passing-a-url-with-brackets-to-curl

问题:

curl -X GET -H 'Content-Type: application/json'  -H 'Date: 1666324656' -H 'https://rule.cn/api/pcap/downloadForTest?body=[1290,1290]'

curl: (3) [globbing] error: bad range specification after pos ..

解决:

575

Add -g to your command:

-g, --globoff
      This option switches off the "URL globbing parser". When you set this option, you can
      specify URLs that contain the letters {}[] without having curl itself interpret them.
      Note that these letters are not normal legal URL contents but they should be encoded
      according to the URI standard.

      Example:
       curl -g "https://example.com/{[]}}}}"

curl.se/docs/manpage.html#-g


2022年7月26日星期二

curl发送gzip压缩数据

参考:https://stackoverflow.com/questions/44307771/curl-command-a-gzipped-post-body-to-an-apache-server 15 Single line: echo '{"mydummy": "json"}' | gzip | curl -v -i --data-binary @- -H "Content-Encoding: gzip" http://localhost/mymodule

2021年11月2日星期二

转:shell 中 urlencode

 https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command


方法一:

sed -f  url_escape.sed

And if you really really feel that you need an external tool (well, it will go a lot faster, and might do binary files and such...) I found this on my OpenWRT router...

replace_value=$(echo $replace_value | sed -f /usr/lib/ddns/url_escape.sed)

Where url_escape.sed was a file that contained these rules:

# sed url escaping
s:%:%25:g
s: :%20:g
s:<:%3C:g
s:>:%3E:g
s:#:%23:g
s:{:%7B:g
s:}:%7D:g
s:|:%7C:g
s:\\:%5C:g
s:\^:%5E:g
s:~:%7E:g
s:\[:%5B:g
s:\]:%5D:g
s:`:%60:g
s:;:%3B:g
s:/:%2F:g
s:?:%3F:g
s^:^%3A^g
s:@:%40:g
s:=:%3D:g
s:&:%26:g
s:\$:%24:g
s:\!:%21:g
s:\*:%2A:g


方法二:

 use jq:

$ printf %s 'encode this'|jq -sRr @uri
encode%20this
$ jq -rn --arg x 'encode this' '$x|@uri'
encode%20this

2021年9月14日星期二

非空格的空白符C2A0

 问题:

curl 是出现“-bash: curl XXXX: No such file or directory ” 的提示,如下:

# curl 'http://127.0.0.1:8083/v1/get/agentNum?begin_time=1621262245'

-bash: curl http://127.0.0.1:8083/v1/get/agentNum?begin_time=1621262245: No such file or directory

处理:
这里的curl 与‘直接的空白有问题,查了一下二进制如下区别:
 6cc2 a027 0d0a 6c20 270d 0a              l..'..l '..
空格是 20
而这个有有问题的空白是c2a0

[go]了一下是 

至于为什么会出现这样的情况,是不是因为富文本编辑器本身就对空白做了处理的。

自己的是别人发过来的code,下次看到这个 “-bash: XXXX: No such file or directory” ,小心一下空格吧,看到的都是假的啊!!!


参考:https://segmentfault.com/q/1010000002754028

2021年5月9日星期日

转:curl网络连接显示

 地址:https://zhuanlan.zhihu.com/p/102001493


curl \       
 --write-out "%{http_code},%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_appconnect},%{time_starttransfer}\n" \    
    --silent \    

详细说明


%{http_code},接口状态码

%{time_total}, 从开始到请求完毕的时间,响应完毕

%{time_namelookup},从开始到dns解析完成的时间

%{time_connect},从开始到链接完成的时间

%{time_pretransfer}, 从开始到请求开始传输的时间

%{time_appconnect}, 从开始到tls,ssl建立链接完毕的时间

%{time_starttransfer},从开始到第一个字节开始传输的时间


2020年6月4日星期四

curl 同时上传file和json方式


curl -i -X POST \
-F "occtime=1591252352" \
-F "src_port=8099" \
-F "proto=6" \
-F "file_name=\"./_tfile\"" \
-F "uri=\"/url_t/tip_test_use/sample/docx/_tfile\"" \
-F "app_proto=\"http\"" \
-F "src_ip=\"192.168.100.120\"" \
-F "host=\"192.168.100.120\"" \
-F "state=CLOSED" \
-F "user_agent=Wget/1.14 (linux-gnu)" \
-F "time=01/22/2019-17=45=09.549569" \
-F "magic=Zip archive data" \
-F "sha256=uffd9a82a374742074e23ea13661b0a89db7176c9f6868c1ac3486efec64758dc" \
-F "dest_port=39176" \
-F "dest_ip=\"10.9.184.225\"" \
-F "size=499318" \
-F "file=@./_tfile" 
http://192.168.100.81:1809/file_upload/upload
参考:https://aiezu.com/article/linux_curl_getpost_datafile_json.html
注意:"-F"与"-d"有一点不同,"-d"可以使用“-d 'a=1&b=2'”将两个字段放一起;而"-F"不行,一个"-F"只能包含一个key/value对,如:"-F a=1 -F b=2"。
 
1、提交key/value值对数据(--form-F):
1
2
3
4
5
6
7
8
9
10
11
[root@aiezu.com ~]# curl --form 'name=爱E族' -F "site=aiezu.com" http://aiezu.com/test.php
[REQUEST_METHOD]: POST
[CONTENT_LENGTH]: 248
[CONTENT_TYPE]: multipart/form-data; boundary=----------------------------71b11083beb3
 
$_POST:
Array
(
    [name] => 爱E族
    [site] => aiezu.com
)

2019年3月13日星期三

转:curl 使用https


https://blog.csdn.net/bytxl/article/details/46989667

$ wget 'https://x.x.x.x/get_ips' --no-check-certificate
curl 'https://x.x.x.x/get_ips' -k

2018年11月15日星期四

curl 同时使用-F,-d ,Warning: You can only select one HTTP request


参考:https://curl.haxx.se/mail/archive-2003-07/0049.html


To upload a file you have to use multipart/form-data encoding. 

With -d your data is sent application/x-www-form-urlencoded,  
with -F as required as multipart/form-data. 
[popexizhi: 参数对请求头的控制 ]
Thus, your command line should be 

curl -F "photo=@1.gif;type=image/gif" -F adv_id= -F MAX_FILE_SIZE=1000000 ... 
Alternatively you can try whether your server does understand a mix of GET and
POST parameters: 
curl -F "photo=@1.gif;type=image/gif" "http://...?adv_id=&MAX_FILE_SIZE=10..." 


原始问题描述:
On Tuesday 08 July 2003 13:04, Brano wrote:
> Hi curl-users_at_lists.sourceforge.net, 

> I want fill in form, and also upload picture at the same time, but I 
> dont know how to do it: 

> curl -F "photo=@1.gif;type=image/gif" -d 
> "adv_id=&MAX_FILE_SIZE=1000000&firm=VSetko&email=vsetko_at_hotmail.com&subsect 
>ion=59&location=1&want_to=100&validity=1&text=text inzeratu" "http://..." 

> doesn't work (You can only select one HTTP request!) 

> exist some better way to do that, or I have to: 

> curl -F "photo=@1.gif;type=image/gif" -F "adv_id=" -F 
> "MAX_FILE_SIZE=1000000" ... ? 

2018年11月9日星期五

curl http返回,超时为000



shell curl 取得HTTP返回的状态码

curl -I -m 10 -o /dev/null -s -w %{http_code} ww.163.cn
但是返回的是000,go了一下

https://segmentfault.com/q/1010000008718022

因为指定了选项-w %{http_code},当域名不存在或连接超时时,返回的值即为000

2018年5月3日星期四

https _ip curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate.



http://www.cnblogs.com/weifeng1463/p/8582921.html


[root@localhost ~]# curl https://pre.bjy****.com/wec****-server/
curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate.
curl https 网站 出现报错 
解决办法:
You can use the domain name as usual but override the resolver like so:
curl -v --resolve subdomain.example.com:443:x.x.x.x https://subdomain.example.com/
It might be awkward to maintain a lot of such mappings though. You might prefer to just ignore the cert mismatch:
curl --insecure https://subdomain.example.com/