curl:(3)在URL中发现非法字符 [英] curl: (3) Illegal characters found in URL

查看:5856
本文介绍了curl:(3)在URL中发现非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要批量查找 ip详情ipinfo.io 这是我的代码。
$ cat ips.txt | xargs -I%curl http://ipinfo.io/%/region



文件ips.txt包含三个ip地址在单独的行上:
(1)8.8.8.8
(2)8.8.4.4
(3)1.2.3.4



这将只解析最后一个ip地址。它应该给(1)加利福尼亚(2)科罗拉多州(3)华盛顿。我得到如下:


curl:(3)URL中发现非法字符
curl:(3)发现非法字符URL
Washington


如果我写ips.txt只有一个ip地址(例如8.8.8.8)结果。我认为有一些问题,我的文本文件或我使用cat的方式。你能帮助我清理我的代码,使所有三个IP地址解决?



每个请求,这里是我的设置的详细信息。

  $ uname -a 
CYGWIN_NT-10.0 OFFICECOMP 2.3.1(0.291 / 5/3)2015-11-14 12:44 x86_64 Cygwin
$ curl -V
curl 7.45.0(x86_64- unknown-cygwin)libcurl / 7.45.0 OpenSSL / 1.0.2d zlib / 1.2.8 lib idn / 1.29 libssh2 / 1.5.0
协议:dict文件ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
特性:调试IDN IPv6大文件GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets元


解决方案

总结一下,作为将来参考的一步一步,



code> uname -A 可以揭示正在使用的系统,例如这里显示的是Cygwin。



关于Windows和Linux的差异。



已知的差异之一是windows / dos行尾。这可以透露,以及通常检查文本文件的所有内容,具有:

  cat -A ips.txt 

现在如果你发现它包含 ^ M 行结束,因为它在这里,这意味着行结束是dos /窗口,而不是* nix行结束(这将只显示以 $ 结尾的行)



要解决这个问题,只需运行

  dos2unix ips.txt 

现在,如果你用这个固定的输入文件运行你的原始命令,CURL看起来很高兴,它工作。 / p>

谢谢你和MistaGill,我从这篇文章中了解到 ipinfo.io


I want to bulk lookup ip details at ipinfo.io Here is my code. $ cat ips.txt | xargs -I% curl http://ipinfo.io/%/region

The file "ips.txt" contains three ip addresses each on a separate line: (1) 8.8.8.8 (2) 8.8.4.4 (3) 1.2.3.4

This resolves only the last ip address. It should give (1) California (2) Colorado (3) Washington. I get the below:

curl: (3) Illegal characters found in URL curl: (3) Illegal characters found in URL Washington

If I write ips.txt with only one ip address (for example 8.8.8.8) I get good results. I think there is something wrong with either my text file or the way I am using cat. Can you help me clean my code so that all three ip addresses are resolved?

Per request, here are details of my setup.

$ uname -a
CYGWIN_NT-10.0 OFFICECOMP 2.3.1(0.291/5/3) 2015-11-14 12:44 x86_64 Cygwin
$ curl -V
curl 7.45.0 (x86_64-unknown-cygwin) libcurl/7.45.0 OpenSSL/1.0.2d zlib/1.2.8 lib idn/1.29 libssh2/1.5.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: Debug IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets Metali

解决方案

So to summarize, as a step-by step for future reference,

Running uname -A can reveal what system is being used for example revealing here it is Cygwin.

This leads us to thinking about Windows vs Linux differences.

One of the known differences are windows/dos line endings. This can be revealed, as well as with generally checking all contents of a text file, with:

cat -A ips.txt

Now if you find it contains ^M line endings, as it did here, it means the line endings are dos/windows and not *nix line endings (which would show only lines ending with $)

To fix this, simply run

dos2unix ips.txt

Now, if you run your original command with this fixed input file, it seems CURL is happy with it and it works.

Thank you as well MistaGill, I learned about ipinfo.io from this post.

这篇关于curl:(3)在URL中发现非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆