Oct
29
对于HEAD和GET,已经比较了解了,但是对POST发送的请求格式特别是HTTP实体,尤其是带有文件的HTTP请求,还很不了解,于是刚刚用PHP写了一个简单的"服务器"程序,看看浏览器到底给我发了什么,代码如下:
1. server.php
很简单的一个脚本,等待8080端口的请求,输出请求内容,然后返回一个像模像样的东东。不过需要注意,用浏览器进行请求的时候需要在发送完毕以后点击停止按钮(断开连接),这个脚本才会断开连接。脚本还存在一些其他问题,比如字符0好像输出得不太对头。不过差不多够用,大致可以让我看清楚浏览器发了什么过来。代码如下:
1. server.php
很简单的一个脚本,等待8080端口的请求,输出请求内容,然后返回一个像模像样的东东。不过需要注意,用浏览器进行请求的时候需要在发送完毕以后点击停止按钮(断开连接),这个脚本才会断开连接。脚本还存在一些其他问题,比如字符0好像输出得不太对头。不过差不多够用,大致可以让我看清楚浏览器发了什么过来。代码如下:
Oct
26
By Felix021 @ 2008-10-26 03:41 CST
If you visit http://sourceforge.net/projects/poxy/ , you'll find such statement: As of 2007-09-07 11:55, this project is no longer under active development.
The original authors abandoned this project for abusement of it, but I think it very useful, at least to me who have to download something but have a bad direct connection while via PHProxy on my own webspace I can download with high speed.
由于使用者对poxy的滥用,作者停止了开发,但是对于我这种需要下载某个文件、直接下载很慢但是通过我的空间连接很快的人而言,poxy还是很有用的。
But I found that poxy is designed just for browsing, not optimized for downloading, for example, it doesn't support multi-thread downloadment, so I feel obliged to modify the source code. In fact this is very simple. I added a few lines, and now it works well, supporting multi-thread downloading and pause-continue action. What's more, I added a button for users to obtain download link directly from copying the address shown below.
但是我发现,poxy基本上只是为了浏览而开发的,没有为下载优化过。比如,它不支持多线程下载,所以我觉得有必要去改下源码。实际上非常简单,加上几行代码就行了,现在它工作得很好,不仅支持多线程下载,还支持断点续传。此外,我还增加了一个按钮可以让用户直接获取下载地址。
This version of poxy is based on poxy 0.5b2, where you can get from sourceforge. It's TODO list has 17 features to be completed, and my modification only partial implemented the 9th, 'support HTTP 1.1' . Maybe I'll implement the FTP support in the future (indeed I've written a simple web ftp proxy before).
这个版本的poxy是从0.5b2版本改进而来,你可以在sourceforge上down到。本来作者打算还有17个功能要完成,我的修改部分地完成了功能9,支持HTTP 1.1。也许以后有空的时候我会吧FTP支持也做进去(事实上我已经写了一个在线ftp代理 )。
Modification:
我做的修改
1. added a button and an input field for direct download link
增加一个按钮和输入框,可以直接获取下载地址
2. added HTTP/1.1 'Range' support, now capable of multi-thread downloading
增加对HTTP/1.1 Range(范围)的支持,可以多线程下载了。
3. added HTTP/1.1 'Referer' support, no worry for anti-leech of the server
增解HTTP/1.1 Referer(来源页)的支持,可以突破防盗链(很卑鄙,呵呵。。)
Download here:
If you visit http://sourceforge.net/projects/poxy/ , you'll find such statement: As of 2007-09-07 11:55, this project is no longer under active development.
The original authors abandoned this project for abusement of it, but I think it very useful, at least to me who have to download something but have a bad direct connection while via PHProxy on my own webspace I can download with high speed.
由于使用者对poxy的滥用,作者停止了开发,但是对于我这种需要下载某个文件、直接下载很慢但是通过我的空间连接很快的人而言,poxy还是很有用的。
But I found that poxy is designed just for browsing, not optimized for downloading, for example, it doesn't support multi-thread downloadment, so I feel obliged to modify the source code. In fact this is very simple. I added a few lines, and now it works well, supporting multi-thread downloading and pause-continue action. What's more, I added a button for users to obtain download link directly from copying the address shown below.
但是我发现,poxy基本上只是为了浏览而开发的,没有为下载优化过。比如,它不支持多线程下载,所以我觉得有必要去改下源码。实际上非常简单,加上几行代码就行了,现在它工作得很好,不仅支持多线程下载,还支持断点续传。此外,我还增加了一个按钮可以让用户直接获取下载地址。
This version of poxy is based on poxy 0.5b2, where you can get from sourceforge. It's TODO list has 17 features to be completed, and my modification only partial implemented the 9th, 'support HTTP 1.1' . Maybe I'll implement the FTP support in the future (indeed I've written a simple web ftp proxy before).
这个版本的poxy是从0.5b2版本改进而来,你可以在sourceforge上down到。本来作者打算还有17个功能要完成,我的修改部分地完成了功能9,支持HTTP 1.1。也许以后有空的时候我会吧FTP支持也做进去(事实上我已经写了一个在线ftp代理 )。
Modification:
我做的修改
1. added a button and an input field for direct download link
增加一个按钮和输入框,可以直接获取下载地址
2. added HTTP/1.1 'Range' support, now capable of multi-thread downloading
增加对HTTP/1.1 Range(范围)的支持,可以多线程下载了。
3. added HTTP/1.1 'Referer' support, no worry for anti-leech of the server
增解HTTP/1.1 Referer(来源页)的支持,可以突破防盗链(很卑鄙,呵呵。。)
Download here:
下载文件 (已下载 1490 次)
Oct
13
Oct
11
效果为:点击add按钮在表格中增加一行;点击某行的del连接删除该行。
Oct
11
zz from http://www.blogjava.net/boddi/archive/2006/08/15/63609.html
attachEvent() / addEventListener() 对象添加触发事件(转)
有时候当某一对象的某一事件被触发时,它所要执行的程序可能是一大串,有可能是要呼叫某一函数,也有可能同时又要呼叫另一函数。
document.getElementById("btn").onclick = method1;
document.getElementById("btn").onclick = method2;
document.getElementById("btn").onclick = method3;
如果这样写,那么将会只有medhot3被执行
在IE中使用attachEvent ,
attachEvent() / addEventListener() 对象添加触发事件(转)
有时候当某一对象的某一事件被触发时,它所要执行的程序可能是一大串,有可能是要呼叫某一函数,也有可能同时又要呼叫另一函数。
document.getElementById("btn").onclick = method1;
document.getElementById("btn").onclick = method2;
document.getElementById("btn").onclick = method3;
如果这样写,那么将会只有medhot3被执行
在IE中使用attachEvent ,
Sep
26
用起来挺方便的。
function setCookie(key, value, day) {
day = parseInt(day);
if(!isNaN(day)){
var expireDate = new Date();
expireDate.setTime(expireDate.getTime() + (day*24*3600000));
document.cookie = key + "=" + encodeURIComponent(value) + ";expires=" + expireDate.toGMTString();
}
else{
document.cookie = key + "=" + encodeURIComponent(value);
}
}
function getCookie(str){
var reg = new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
var ck = reg.exec(document.cookie);
try{
if(ck[2] == null || typeof(ck[2]) == "undefine") return null;
}
catch(e){
return null;
}
return decodeURIComponent(ck[2]);
}
day = parseInt(day);
if(!isNaN(day)){
var expireDate = new Date();
expireDate.setTime(expireDate.getTime() + (day*24*3600000));
document.cookie = key + "=" + encodeURIComponent(value) + ";expires=" + expireDate.toGMTString();
}
else{
document.cookie = key + "=" + encodeURIComponent(value);
}
}
function getCookie(str){
var reg = new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
var ck = reg.exec(document.cookie);
try{
if(ck[2] == null || typeof(ck[2]) == "undefine") return null;
}
catch(e){
return null;
}
return decodeURIComponent(ck[2]);
}
Sep
26
在javascript的String对象(字符串)里面没有trim方法,使得很多时候在判断的时候挺无奈
刚刚看到了prototype.js的源码,发现里面实现了这个方法,用的方法其实很简单——
用正则表达式来把首位的空格替换成空串。代码如下
如果要更进一步给String定义一个trim函数,可以用如下代码
非常简单,却非常牛B
刚刚看到了prototype.js的源码,发现里面实现了这个方法,用的方法其实很简单——
用正则表达式来把首位的空格替换成空串。代码如下
replace(/(^\s*)|(\s*$)/g, "");
如果要更进一步给String定义一个trim函数,可以用如下代码
String.prototype.trim = function(){
return this.replace(/^\s*|\s*$/g, "");
}
return this.replace(/^\s*|\s*$/g, "");
}
非常简单,却非常牛B
Sep
23
参考了boblog的UBB代码写了这个函数。
给id为o_id的元素中选中的文本添加o_tag对应的UBB表情
e.g.
addUBB("content", "b");
addUBB("content", "i");
给id为o_id的元素中选中的文本添加o_tag对应的UBB表情
e.g.
addUBB("content", "b");
addUBB("content", "i");
function addUBB(o_id, o_tag){
if(navigator.userAgent.indexOf("MSIE") != -1){ //IE
var sel = document.selection;
var range = sel.createRange();
if(!(sel.type=="Text" && range.parentElement().id==o_id))return;
range.text = "["+o_tag+"]"+range.text+"[/"+o_tag+"]";
}else{ //FireFox
var obj = document.getElementById(o_id);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;
if(selStart == selEnd) return;
var a = obj.value.substring(0, selStart);
var b = obj.value.substring(selStart, selEnd);
var c = obj.value.substring(selEnd, obj.value.length);
obj.value=a+"["+o_tag+"]"+b+"[/"+o_tag+"]"+c;
}
}
if(navigator.userAgent.indexOf("MSIE") != -1){ //IE
var sel = document.selection;
var range = sel.createRange();
if(!(sel.type=="Text" && range.parentElement().id==o_id))return;
range.text = "["+o_tag+"]"+range.text+"[/"+o_tag+"]";
}else{ //FireFox
var obj = document.getElementById(o_id);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;
if(selStart == selEnd) return;
var a = obj.value.substring(0, selStart);
var b = obj.value.substring(selStart, selEnd);
var c = obj.value.substring(selEnd, obj.value.length);
obj.value=a+"["+o_tag+"]"+b+"[/"+o_tag+"]"+c;
}
}