Showing posts with label HTTP. Show all posts
Showing posts with label HTTP. Show all posts

Monday, April 18, 2011

linux命令nc使用实例说明

使用netcat检查服务器的指定的端口是否开通:
root@localhost:~$ nc -z -v 192.168.1.242 80
linux.local [192.168.1.242] 80 (www) open

使用netcat扫描端口:
root@localhost:~$ nc -z -v -w 1 192.168.1.242 1-100
linux.local [192.168.1.242] 80 (www) open
linux.local [192.168.1.242] 22 (ssh) open

使用netcat模拟HTTP请求:
root@localhost:~$ nc www.google.com.hk 80
GET / HTTP/1.1
Host: www.google.com.hk
User-Agent: google-chrome9

HTTP/1.1 200 OK
Date: Mon, 18 Apr 2011 08:56:03 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Big5
Set-Cookie: PREF=ID=5006f5c292697224:FF=0:NW=1:TM=1303116963:LM=1303116963:S=Lr6ijyXSbmjA6bmZ; expires=Wed, 17-Apr-2013 08:56:03 GMT; path=/; domain=.google.com.hk
Set-Cookie: NID=46=ky6egq_YajJNEzdnM39_2u3CFq2hJLvSVuQm6BokYXSBKhAefFIuL-ZsZOvnDpMISnI2glY25IZxS8_5G0V-EHj-oEc7KRGW4rSZk9yIRnCgsPnm43qhLUMb9hJuKeVW; expires=Tue, 18-Oct-2011 08:56:03 GMT; path=/; domain=.google.com.hk; HttpOnly
Server: gws
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
[......]

Saturday, July 17, 2010

acme网站上几个http小工具

1. http_load: http://www.acme.com/software/http_load/

同apache ab和JMeter一样可以对数据库和web服务器作压力测试。
$> vi urls


$> ./http_load -rate 5 -seconds 10 urls
49 fetches
2 max parallel
289884 bytes
in 10.0148 seconds 5916 mean bytes/connection 4.89274 fetches/sec
28945.5 bytes/sec msecs/connect: 28.8932 mean
44.243 max
24.488 min msecs/first-response: 63.5362 mean
81.624 max
57.803 min
HTTP response codes: code 200 -- 49

2. http_ping: http://www.acme.com/software/http_ping/

与ping命令类似,但是是通过http请求来检查服务器,而非ICMP请求服务器返回响应。

$> http_ping http://www.example.com/
7816 bytes from http://www.example.com/:
246.602 ms (9.923c/23.074r/213.605d)
7816 bytes from http://www.example.com/:
189.997 ms (11.619c/22.971r/155.407d)
7816 bytes from http://www.example.com/:
190.463 ms (8.994c/25.091r/156.378d)
7816 bytes from http://www.example.com/:
190.07 ms (9.234c/23.9r/156.936d)
7816 bytes from http://www.example.com/:
190.706 ms (10.142c/46.579r/133.985d)
--- http://www.example.com/
http_ping statistics
--- 5 fetches started, 5 completed (100%), 0 failures (0%), 0 timeouts (0%)
total min/avg/max = 189.997/201.568/246.602 ms
connect min/avg/max = 8.994/9.9824/11.619 ms
response min/avg/max = 22.971/28.323/46.579 ms
data min/avg/max = 133.985/163.262/213.605 ms

Monday, November 03, 2008

When iframe src is too long in IE6/IE7

在ie中,如果页面内的iframe src的URL长度过长(>2083),ie会请求失败。
微软官方文档说明如下:
Microsoft Internet Explorer 具有最大统一资源定位符 (URL) 长度为 2,083 个字符。 Internet Explorer 也有最多 2,048 个字符的最大路径长度。 此限制适用于同时 POST 请求和 GET 请求 URL。
如果要使用 GET 方法,您被限制为最多个最多 2,048 个字符,减去的实际路径中的字符数。
但是,POST 方法不受到用于提交名称 / 值对该 URL 的大小。 这些对被传输在标头而不是在该 URL。
RFC 2616,"超文本传输协议--HTTP / 1.1,"未指定 URL 长度的任何要求。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>when iframe src is too long in IE6/IE7</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
If iframe src url size greater than 2083, ie6/ie7 will failure for this http request.
<iframe src="http://localhost/test.php?x=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></iframe>
</script>
</body>
</html>
Reference:http://support.microsoft.com/kb/208427/zh-cn

Saturday, October 11, 2008

Apache SSL证书请求文件(CSR)生成指南

1. 生成私钥 Generate the private key
$> openssl genrsa -des3 -out www.mydomain.com.key 1024
此命令将生成1024位的RSA私钥,私钥文件名为: www.mydomain.com.key,生成过程中会提示设定私钥密码,设置并备份密码,在以后安装证书到apache服务器之后,重启apache服务器时,需要输入此密码验证通过后才能启动!
2. 生成CSR文件 Generate the CSR
$> openssl req -new -key www.mydomain.com.key -out www.mydomain.com.csr
此命令将提示输入X.509证书所要求的字段信息,包括国家(中国添CN)、省份、所在城市、单位名称、单位部门名称(可以不填直接回车)。注意: 除国家缩写必须填CN外,其余都可以是英文或中文。
输入要申请SSL证书的域名,如果为www.domain.com申请SSL证书就不能只输入domain.com,要输入完整的域名,包括二级域名,SSL证书是严格绑定域名的。

Reference: http://www.wosign.com/support/CSRgen/Apache_CSR.htm

Thursday, April 17, 2008

还原apache访问日志中的URL查询字符串

当IE在访问URL:
http://localhost/a.html?q=中文
在apache日志里能看到以下内容:
GET /a.html?q=\xd6\xd0\xce\xc4 HTTP/1.1

而在Firefox中访问相同URL:
日志中看到的内容是对字符串进行urlencode过后的格式:
GET /a.html?q=%D6%D0%CE%C4 HTTP/1.1

现在IE下,\xXX这种看上像2位16进制值XX指定的1个字符(可能是Latin-1字符集的字符),如果想直接还原出“中文”2个字比较困难。
不过在与Firefox中的日志对比之下,能看出只要直接将\x替换成%,然后用PHP的urldecode反解析就能得到对应的字符串。

另外说明一点:
这个例子中看到的值%D6%D0%CE%C4,是按gbk字符集进行urlencode计算得到的对应值,如果urldecode反解析得到是乱码,则日志记录的应该是utf-8格式的urlencode值,用PHP的iconv函数处理一下。

Tuesday, April 08, 2008

HTTP request and response headers examples using telnet

yu$ telnet www.google.com 80
Trying 64.233.189.99...
Connected to www.l.google.com.
Escape character is '^]'.
GET /intl/en_ALL/images/logo.gif HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate

HTTP/1.1 200 OK
Content-Type: image/gif
Last-Modified: Wed, 07 Jun 2006 19:38:24 GMT
Expires: Sun, 17 Jan 2038 19:14:07 GMT
Server: gws
Content-Length: 8558
Age: 13
Date: Sun, 06 Apr 2008 06:51:56 GMT

GIF89an.....

yu$ telnet www.google.com 80
Trying 64.233.189.104...
Connected to www.l.google.com.
Escape character is '^]'.
GET /intl/en_ALL/images/logo.gif HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate
If-Modified-Since: Wed, 07 Jun 2006 19:38:24 GMT

HTTP/1.1 304 Not Modified
Date: Sun, 06 Apr 2008 06:53:10 GMT
Server: GFE/1.3

yu$ telnet l.yimg.com 80
Trying 203.209.246.249...
Connected to geoycs-l.yahoo8.akadns.net.
Escape character is '^]'.
GET /a/i/ww/news/2008/04/04/crocodile-sm.jpg HTTP/1.1
Host: l.yimg.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate
Connection: keep-alive

HTTP/1.1 200 OK
Date: Sat, 05 Apr 2008 00:14:27 GMT
Cache-Control: max-age=315360000
Expires: Tue, 03 Apr 2018 00:14:27 GMT
Last-Modified: Fri, 04 Apr 2008 17:49:26 GMT
Accept-Ranges: bytes
Content-Length: 860
Content-Type: image/jpeg
Age: 133250
Connection: keep-alive
Server: YTS/1.16.0



Connection closed by foreign host.

In HTTP/1.1 the ETag and If-None-Match headers are another way to make conditional GET requests.

<IMG ALT="Red Star"
SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWW
lvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEA
AAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBia
tt2H1KBLQRFIJAIKywRgmhwAIlEEADs=">

Apache2 mod_headers using to modify http response headers

将mod_headers.so复制到modules目录下,修改httpd.conf文件:

LoadModule headers_module modules/mod_headers.so
Header add P3P "CP=\"CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""
Header set TEST "%D %t"

其中Header可添加在Context: server config, virtual host, directory, .htaccess
Reference: http://httpd.apache.org/docs/1.3/mod/mod_headers.html
http://httpd.apache.org/docs/2.2/mod/mod_headers.html

Saturday, March 22, 2008

Google AJAX Language API - Basic Scripting HTTP Request


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Language API - Basic Translation</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">

google.load("language", "1");

function initialize() {
google.language.translate("Hello world", "en", "zh-CN", function(result) {
if (!result.error) {
var container = document.getElementById("translation");
container.innerHTML = result.translation;
}
});

var text = "简体中文测试";
google.language.detect(text, function(result) {
if (!result.error) {
var language = 'unknown';
for (l in google.language.Languages) {
if (google.language.Languages[l] == result.language) {
language = l;
break;
}
}
var container = document.getElementById("detection");
container.innerHTML = text + " is: " + language + "";
}
});
}
google.setOnLoadCallback(initialize);

</script>
</head>
<body>
<div id="translation"></div>
<div id="detection"></div>
</body>
</html>

Google get response and execute response text through scripting http request. Scripting HTTP Request step:
  • First add an dynamic "script" node after head, even if document source have not head tag, javascript will still run right. If add "script" node to document.body node, javascript may be error because javascript can't get body element.
  • Then set this "script" node "src" to get google translate service, and it will return a javascript statement, and when "script" loaded, it will be executed auto.
  • At last, Delete this "script" node.
Here is an simple example:
1. javascript file - "getTextWithScript.js";

var getTextWithScript = function(callback) {
// Create a new script element and add it to the document.
var head=document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type="text/javascript";
script.charset="utf-8";
head.appendChild(script);

// Get a unique function name.
var funcname = "func" + getTextWithScript.counter++;

// Define a function with that name, using this function as a
// convenient namespace. The script generated on the server
// invokes this function.
getTextWithScript[funcname] = function() {
// Pass the text to the callback function
callback(Array.prototype.slice.call(arguments));

// Clean up the script tag and the generated function.
script.onload = null;
head.removeChild(script);
delete script;
delete getTextWithScript[funcname];
}

// Encode the URL we want to fetch and the name of the function
// as arguments to the jsquoter.php server-side script. Set the src
// property of the script tag to fetch the URL.
script.src = "jsquoter.php" + "?func=" + encodeURIComponent("getTextWithScript." + funcname);
}

// We use this to generate unique function callback names in case there
// is more than one request pending at a time.
getTextWithScript.counter = 0;

2. server process request file - "jsquoter.php";

<?php
// Tell the browser that we're sending a script
header("Content-Type: text/javascript");
// Get arguments from the URL
$func = $_GET["func"];
// process
echo "$func('test', 'from', 'php', 'file');";
?>

3. test file - "getTextWithScript.html":

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Scripting HTTP</title>
<script type="text/javascript" src="getTextWithScript.js"></script>
<script type="text/javascript">
function callback(){
document.getElementById('main').innerHTML = arguments[0].join(" ");
}
getTextWithScript(callback);
</script>
</head>
<body>
<div id="main"></div>
</body>
</html>

test file will get result: "test from php file"

Wednesday, March 19, 2008

PHP5 get http response body using CURL library

get response body of specified web page using php5, such as google homepage.

<?php
ob_start();

$ch = curl_init("http://www.google.com/");
curl_exec($ch);
curl_close($ch);
$retrievedhtml = ob_get_contents();
ob_end_clean();
// ob_end_flush();

echo $retrievedhtml;
?>

Thursday, January 31, 2008

HTTP status list

200 : request completed (OK)
201 : object created, reason = new URI
202 : async completion (TBS)
203 : partial completion
204 : no info to return
205 : request completed, but clear form
206 : partial GET furfilled
300 : server couldn't decide what to return
301 : object permanently moved
302 : object temporarily moved
303 : redirection w/ new access method
304 : if-modified-since was not modified
305 : redirection to proxy, location header specifies proxy to use
307 : HTTP/1.1: keep same verb
400 : invalid syntax
401 : access denied
402 : payment required
403 : request forbidden
404 : object not found
405 : method is not allowed
406 : no response acceptable to client found
407 : proxy authentication required
408 : server timed out waiting for request
409 : user should resubmit with more info
410 : the resource is no longer available
411 : the server refused to accept request w/o a length
412 : precondition given in request failed
413 : request entity was too large
414 : request URI too long
415 : unsupported media type
500 : internal server error
501 : required not supported
502 : error response received from gateway
503 : temporarily overloaded
504 : timed out waiting for gateway
505 : HTTP version not supported

Thursday, December 20, 2007

document referer and referrer

http request referer:
Referer http://www.google.cn/search?hl=zh-CN&q=%E6%B5%B7%E8%AF%8D&btnG=Google+%E6%90%9C%E7%B4%A2&meta=

php $_SERVER['http_referer']:
http://www.google.cn/search?hl=zh-CN&q=%E6%B5%B7%E8%AF%8D&btnG=Google+%E6%90%9C%E7%B4%A2&meta=

javascript referer:
document.referrer

Wednesday, December 05, 2007

Wednesday, April 04, 2007

安装subversion报错 URL scheme Unrecognized

subversion和subversion-deps的当前版本都已经是1.4.4


[root@localhost tmp]$ svn co http://www.gnome-dock.org/svn/ .
svn: Unrecognized URL scheme for 'http://www.gnome-dock.org/svn'

在安装subversion1.4.3之前需要先装它的全部依赖包
http://subversion.tigris.org/downloads/subversion-deps-1.4.0.tar.bz2
./configure --prefix=/usr/local/apr
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
./configure --prefix=/usr/local/neon
./configure --prefix=/usr/local/zlib

./configure \
--prefix=/usr/local/subversion \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-apxs=/usr/local/apache2/bin/apxs \
--with-neon=/usr/local/neon \
--with-ssl \
--with-zlib \
--enable-maintainer-mode

Wednesday, March 28, 2007

HTTP_REFERER问题

点击某个链接经过跳转页后到达目标页面时,目标页面取到的HTTP_REFERER_URL为点击链接所在页面的URL,而不是跳转页。也就是说直接从浏览器里进去是跳转页,跳到目标页面时,是取不到HTTP_REFERER的。
另:点Flash页面过来取不到HTTP_REFERER_URL。