使用curl模拟HTTP请求 [英] simulate an HTTP request with curl

查看:346
本文介绍了使用curl模拟HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试调试在我们的服务器上产生错误的HTTP请求。



在我的nginx日志中,我看到这个条目生成错误



157.55.33.20 - - [22 / Nov / 2013:04:06:22 +0000]GET / en / library / search?utf8 = \xE2\x9C\\ \\ x93& q = something HTTP / 1.1500 0 - Mozilla / 5.0(compatible; bingbot / 2.0; + http://www.bing.com/bingbot.htm) -



但是,尝试使用 curl httpie 使用相同的字符串生成如下日志条目:



GET / en / library / search?utf8 = \x5CxE2\x5Cx9C\x5Cx93& ; q = something





GET / en / library / search?utf8 = xE2x9Cx93& q = something





GET / en / library / search?utf8 =%5CxE2%5Cx9C%5Cx93& q = something



只是不能似乎重现完全相同的请求。



有关如何重现完全相同的请求的任何建议?

解决方案

您可以使用telnet更自由地创建HTTP请求。要启动连接,请在命令行输入:

  telnet www.example.com 80 

(这里,80对应于HTTP请求的端口号)。连接后,您会看到类似如下的讯息:

 尝试12.34.56.78 ... 
已连接到www.example.com。
转义字符是'^]'。

然后,您可以输入您的请求,例如:

  GET / en / library / search?utf8 = \xE2\x9C\x93& q = something HTTP / 1.1 
Host:www.example.com
User-Agent:Mozilla / 5.0(compatible; bingbot / 2.0; + http://www.bing.com/bingbot.htm)
接受:text / html,application / xhtml + xml,application /xml;q=0.9,*/*;q=0.8

完成两个回车符

。lcornea的建议也值得考虑。如果你的命令行终端
接受UTF8(输入 echo $ LANG 找出),然后键入(或粘贴)字符✓
标记)而不是三个转义字符。或者在Windows Latin-1终端上,
改为输入 - 。



I'm trying to debug an HTTP request that produces an error on our server. However, I'm struggling to reproduce the exact request somehow.

On my nginx logs, I see this entry which generated the error

157.55.33.20 - - [22/Nov/2013:04:06:22 +0000] "GET /en/library/search?utf8=\xE2\x9C\x93&q=something HTTP/1.1" 500 0 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" "-"

However, trying to use curl or httpie using the same string produces log entries like:

GET /en/library/search?utf8=\x5CxE2\x5Cx9C\x5Cx93&q=something

or

GET /en/library/search?utf8=xE2x9Cx93&q=something

or

GET /en/library/search?utf8=%5CxE2%5Cx9C%5Cx93&q=something

I just can't seem to reproduce the exact same request. I tried with various command-line parameters, but can't figure this one out.

Any suggestions on how to reproduce the exact same request?

解决方案

You can create HTTP requests with greater freedom with telnet. To start a connection, type this at the command line:

telnet www.example.com 80

(Here, 80 corresponds to the port number for HTTP requests). Once you're connected, you'll see a message like this:

Trying 12.34.56.78...
Connected to www.example.com.
Escape character is '^]'.

You can then type in your request, e.g.:

GET /en/library/search?utf8=\xE2\x9C\x93&q=something HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Finish with two carriage returns to mark the end of the header.

EDIT: lcornea's suggestion is also worth considering. If your command line terminal accepts UTF8 (type in echo $LANG to find out), then type (or paste) the character ✓ (check mark) instead of the three escaped characters. Or on a Windows Latin-1 terminal, type in âœ" instead.

这篇关于使用curl模拟HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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