标签:curl

curl 查公网IP,外网IP的方法

No Comments 脚本技巧

命令行查询(详细):

  • UNIX/Linux:#curl cip.cc
  • Windows:>telnet cip.cc
  • >ftp cip.cc

命令行查询(纯ip):

  • UNIX/Linux:

CURL不能访问 但浏览器可以访问

No Comments IT小技巧

 

向某网站提交查询,

curl -v http://api.qq.net/apiv2/userinfo/get?apiUser=jeff&apiKey=2we234236t234

一直提示{"result":false,"statusCode":40005,"message":"认证失败","info":{}}

curl -H
CURL -A
都试过不行。

使用curl -v 进行查询定位问题

------中间广告---------

curl -v http://api.qq.net/apiv2/userinfo/get?apiUser=jeff&apiKey=2we234236t234
[1] 4199
[root@hk-ops-ser-zabbix-001 bak]# * About to connect() to api.qq.net port 80 (#0)
*   Trying 106.75.106.147…
* Connected to api.qq.net  port 80 (#0)
> GET /apiv2/userinfo/get?apiUser=jeff HTTP/1.1         #——-注意这个地方。发现没有提交密码
> User-Agent: curl/7.29.0
> Host: api.qq.net
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.12.1
< Date: Thu, 15 Nov 2018 07:05:24 GMT
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
<

结论,有可能是需要对 & 进行转义

解决
进行命令修改  转义 \&

提交

curl -v http://api.qq.net/apiv2/userinfo/get?apiUser=jeff\&apiKey=2we234236t234
About to connect() to api.qq.net port 80 (#0)
*   Trying 106.75.85.126…
* Connected to api.qq.net  port 80 (#0)
> GET /apiv2/userinfo/get?apiUser=jeff&apiKey=2we234236t234 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: api.qq.net
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.12.1
< Date: Thu, 15 Nov 2018 07:06:15 GMT
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
<
* Closing connection 0
{"result":true,"statusCode":200,"message":"请求成功 Done

shell curl 数据中含有空格 如何提交

No Comments IT必备工具

 

如果提交内空带 空格 提交会报错

"msg":"ddddddddddddddddddddddddddd dddddddddddd dddddddddddddd dddddddddd dddddddd"}

curl: (6) Could not resolve host: dddddddddddd; Unknown error
curl: (6) Could not resolve host: dddddddddddddd; Unknown error
curl: (6) Could not resolve host: dddddddddd; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 10

 

解决方案1

 

去掉空格,或用%20等替换

 

将这些字符转化成服务器可以识别的字符,对应关系如下:
URL字符转义

用其它字符替代吧,或用全角的。

+    URL 中+号表示空格                                 %2B   
空格 URL中的空格可以用+号或者编码           %20 
/   分隔目录和子目录                                     %2F     
?    分隔实际的URL和参数                             %3F     
%    指定特殊字符                                          %25     
#    表示书签                                                  %23     
&    URL 中指定的参数间的分隔符                  %26     
=    URL 中指定参数的值                                %3D

 

方案2.

最重要的来了, “$data”  要加双引号

curl -H "Content-Type:application/json" -X POST -d "$data" $url