【发布时间】:2016-08-03 22:00:44
【问题描述】:
我有一个相当简单的 bash 脚本,它可以生成一些像这样的 HTML:
#!/bin/bash
ENV=`echo "${QSTRING}" | sed -n 's/^.*env=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
APP=`echo "${QSTRING}" | sed -n 's/^.*app=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
echo 'Content-type: text/html'
echo ''
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
<... etc ...>
当我像这样运行 curl 命令时,一切正常,脚本返回格式良好的 HTML:
curl --request GET '<url>'
但是当我传递 Mac OS X Chrome 浏览器的用户代理字符串时,我得到一个乱码输出:
curl --request GET '<url>' -A '<user-agent>'
乱码输出如下所示:
17
</select>
<br><br>
45
Delay this install by (hours from now; 0 or blank for deploy now):
68
<input name="delay" type="text" name="delaytime">
<input type="hidden" name="inst" value="test">
5f
<input type="hidden" name="repo" value="test">
<input type="hidden" name="env" value="qa">
6f
<input type="hidden" name="app" value="web">
<br>
<input name="subbtn" value="Submit" type="submit"><br>
29
<p><br>
</p>
</form>
</body>
</html>
0
HTTP/1.1 400 Bad Request
Date: Wed, 03 Aug 2016 20:51:03 GMT
Server: Apache/2.4.12 (Amazon) PHP/5.5.26
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
顶部是预期的 HTML 文本的中间部分,插入了一些十六进制代码。
知道发生了什么吗?
【问题讨论】:
标签: html curl cgi user-agent