程序天空

系统程序开发
posts - 52, comments - 34, trackbacks - 1, articles - 28

HTTP-GET和HTTP-POST

Posted on Friday, January 14, 2005 6:19 PM #Web应用程序开发
HTTP-GET和HTTP-POST

  HTTP-GET和HTTP-POST是使用HTTP的标准协议动词,用于编码和传送变量名/变量值对参数,并且使用相关的请求语义。每个HTTP-GET和HTTP-POST都由一系列HTTP请求头组成,这些请求头定义了客户端从服务器请求了什么,而响应则是由一系列HTTP应答头和应答数据组成,如果请求成功则返回应答。

  HTTP-GET以使用MIME类型application/x-www-form-urlencoded的urlencoded文本的格式传递参数。Urlencoding是一种字符编码,保证被传送的参数由遵循规范的文本组成,例如一个空格的编码是"%20"。附加参数还能被认为是一个查询字符串。

  与HTTP-GET类似,HTTP-POST参数也是被URL编码的。然而,变量名/变量值不作为URL的一部分被传送,而是放在实际的HTTP请求消息内部被传送。

Feedback

# .net中中文乱码问题解决

1/14/2005 6:22 PM by xinxi100
.net中中文乱码问题解决
2004-11-21 23:08:17 (文章类别:.Net)

asp.net默认的编码为utf-8,当与其它平台交互处理的字符串中有中文时往往会出现乱码,这是由于其它平台多采取GB2312编码,要解决这一问题,可编写一个函数,对字符串先转换再处理就行了,下面是该函数的源代码:

Imports System.Math

Function URLEncoding(ByVal vstrIn As String)
Dim strReturn As String
strReturn = ""
Dim i As Integer

Dim ThisChr As String

Dim innerCode, Hight8, Low8 As Integer

For i = 1 To vstrIn.Length

ThisChr = Mid(vstrIn, i, 1)

If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00) \ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function

# re: HTTP-GET和HTTP-POST

1/14/2005 6:26 PM by 欣禧博客
KeyLife富翁笔记
作者: apollo13
标题: Js中实现拼音和UrlEncode的功能(利用GB和Unicode对照表)
关键字:
分类: 个人专区
密级: 公开
(评分: , 回复: 0, 阅读: 87) »»
经常用vb写的urlencoding很容易实现UrlEncode,以及利用
http://www.csdn.net/Develop/read_article.asp?id=13846
中的代码很容易改写成vbs从而实现部分汉字的拼音

但由于有些人需要完全用javascript写,而javascript默认是Unicode
所以就需要一个Unicode和GB的转换库

Unicode和GB的转换库和UrlEncode和getSpell函数,请下载
http://www.blueidea.com/user/qswh/qswhU2GB.js

var qswhU2GB=[];//Unicode和GB的对应表,略
var qswhSpell=[];//拼音的对照表,略

function UrlEncode(str){
var i,c,ret="",strSpecial="!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%";
for(i=0;i<str.length;i++){
if(str.charCodeAt(i)>=0x4e00){
c=qswhU2GB[str.charCodeAt(i)-0x4e00];
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}
else{
c=str.charAt(i);
if(c==" ")
ret+="+";
else if(strSpecial.indexOf(c)!=-1)
ret+="%"+str.charCodeAt(i).toString(16);
else
ret+=c;
}
}
return ret;
}

function getSpell(str,sp){
var i,c,t,ret="";
if(sp==null)sp="";
for(i=0;i<st

# re: HTTP-GET和HTTP-POST

1/14/2005 6:28 PM by 欣禧博客
汉字转化为拼音(asp版) 选择自 qiushuiwuhen 的 Blog
关键字 汉字 拼音 asp Dictionary
出处

很多问题都是因为中文问题造成的
如文件名最好别用中文
现在的解决方法一般是产生一个ID,将这个ID做文件名
网页上如果url带汉字也经常出错
现在的解决方法一般用urlencode编码

现在用了这个转化,就好多了

原理,使用Dictionary技术
1.添加索引
2.遍历词典

<%
Set d = CreateObject("Scripting.Dictionary")
d.add "a",-20319
d.add "ai",-20317
d.add "an",-20304
d.add "ang",-20295
d.add "ao",-20292
d.add "ba",-20283
d.add "bai",-20265
d.add "ban",-20257
d.add "bang",-20242
d.add "bao",-20230
d.add "bei",-20051
d.add "ben",-20036
d.add "beng",-20032
d.add "bi",-20026
d.add "bian",-20002
d.add "biao",-19990
d.add "bie",-19986
d.add "bin",-19982
d.add "bing",-19976
d.add "bo",-19805
d.add "bu",-19784
d.add "ca",-19775
d.add "cai",-19774
d.add "can",-19763
d.add "cang",-19756
d.add "cao",-19751
d.add "ce",-19746
d.add "ceng",-19741
d.add "cha",-19739
d.add "chai",-19728
d.add "chan",-19725
d.add "chang",-19715
d.add "chao",-19540
d.add "che",-19531
d.add "chen",-19525
d.a

# re:多语言混显的问题

1/14/2005 6:32 PM by 欣禧博客
多语言混显的问题
http://Www.Qcsky.Com 9/15/2001 青创网络

  
因为一直不信Java竟会有不能混排显示多国语言的BUG,这个周末研究了一下Servlet、
Jsp的多国语言显示的问题,也就是Servlet的多字符集问题,由于我对字符集的概念还
不是很清晰所以写出的东西未必是准确的,我是这样理解Java中的字符集的:在运行时
,每个字符串对象中存储的都是编码为UNICODE内码的(我觉得所有的语言中都是有相应
编码的,因为在计算机内部字符串总是用内码来表示的,只不过一般计算机语言中的字
符串编码时平台相关的,而Java则采用了平台无关的UNICODE)。

  Java从一个byte流中读取一个字符串时,将把平台相关的byte转变为平台无关的Un
icode字符串。在输出时Java将把Unicode字符串转变为平台相关的byte流,如果某个Un
icode字符在某个平台上不存在,将会输出一个'?'。举个例子:在中文Windows中,Jav
a读出一个"GB2312"编码的文件(可以是任何流)到内存中构造字符串对象,将会把GB2
312编码的文字转变为Unicode编码的字符串,如果把这个字符串输出又将会把Unicode字
符串转化为GB2312的byte流或数组:"中文测试"----->"\u4e2d\u6587\u6d4b\u8bd5"--
--->"中文测试"。

如下例程:
byte[] bytes = new byte[]{(byte)0xd6, (byte)0xd0, (byte)0xce, (byte)0xc4,
(byte)0xb2, (byte)0xe2, (byte)0xca, (byte)0xd4};//GBK编码的"中文测试"
java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(bytes);
java.io.BufferedReader reader = new java.io.BufferedReader(new java.io. Inpu
tStreamReader (bin,"GBK"));
String msg = reader.readLine();
S

# re: urlencode(PHP 3, PHP 4 , PHP 5)

1/14/2005 6:37 PM by 欣禧博客
urlencode
(PHP 3, PHP 4 , PHP 5)

urlencode -- 编码 URL 字符串
描述
string urlencode ( string str)


返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 application/x-www-form-urlencoded 的媒体类型编码方式一样。由于历史原因,此编码在将空格编码为加号(+)方面与 RFC1738 编码(参见 rawurlencode())不同。此函数便于将字符串编码并将其用于 URL 的请求部分,同时它还便于将变量传递给下一页: 例子 1. urlencode() 示例

<?php
echo '<a href="mycgi?foo=', urlencode($userinput), '">';
?>



注意:小心与 HTML 实体相匹配的变量。像 &amp、&copy 和 &pound 都将被浏览器解析,并使用实际实体替代所期待的变量名。这是明显的混乱,W3C 已经告诫人们好几年了。参考地址:http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 PHP 通过 arg_separator .ini 指令,支持将参数分割符变成 W3C 所建议的分号。不幸的是大多数用户代理并不发送分号分隔符格式的表单数据。较为简单的解决办法是使用 &amp; 代替 & 作为分隔符。你不需要为此修改 PHP 的 arg_separator。让它仍为 &,而仅使用 htmlentities(urlencode($data)) 对你的 URL 进行编码。

例子 2. urlencode() 与 htmlentities() 示例

<?php
echo '<a href="mycgi?foo=', htmlentities(urlencode($userinput)), '">';
?>



参见 urldecode()、htmlentities()、rawurldecode() 与 rawurlencode()。

# re: HTTP-GET和HTTP-POST

1/14/2005 6:39 PM by 欣禧博客
Function URLEncodeString(ByVal str As String) As String 'iso-8859-1 URLEncode

Dim intAscii As Integer, I As Long, strTemp As String
strTemp = ""

For I = 1 To Len(str)
intAscii = Asc(Mid(str, I, 1))
If intAscii <= 15 Then
'modify by 酚 2004/09/09
'strTemp = strTemp & "%" & Hex(intAscii) 'encode,fix length
strTemp = strTemp & "%" & Left(Hex(intAscii), 2) & "%" & Right(Hex(intAscii), 2)
ElseIf intAscii = 32 Then
strTemp = strTemp & "+" 'special encode
ElseIf intAscii >= 48 And intAscii <= 57 Then 'number,no encode
strTemp = strTemp & Chr(intAscii)
ElseIf intAscii >= 65 And intAscii <= 90 Then 'English,no encode
strTemp = strTemp & Chr(intAscii)
ElseIf intAscii >= 97 And intAscii <= 122 Then 'English,no encode
strTemp = strTemp & Chr(intAscii)
ElseIf intAscii = 255 Then
strTemp = strTemp & "%FF"

# re: URLEncoding 欣禧博客

1/14/2005 6:47 PM by 欣禧博客


代码见下:
<SCRIPT language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function

Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))

# re: HTTP-GET和HTTP-POST

1/14/2005 6:47 PM by 欣禧博客
Fengdongren 's WebLog - 博客.CN[blogger.cn/blog/中国/china]
... 中间停了一个多月, 幸好得到网友天之痕的提醒, 现在决定把WebLRC V2.0做好后就停止
有关ASP的开发. (可惜又要断网了, 只能等到学校再发布了, ... Function URLEncoding(vstrIn)
strReturn = "" For i = 1 To Len(vstrIn) ThisChr = Mid(vStrIn,i,1) ...

www.mblogger.cn/computer.mblogger.cn/fengdongren/

# re: HTTP-GET和HTTP-POST

1/14/2005 6:49 PM by 欣禧博客
搞定系统中的中文问题
在http传送的过程中,编码的原理:
(1)如果是以post的方式传送:ie自己将它编码成utf-8(或许是iso-8859,这个问题我自己也搞的不清楚),服务器端要使用类似title=new string(request.getparameter("title").getBytes("8859_1"),"gb2312");的命令将它得到.
(2)如果是以get的方式传诵,url是类似title=xxxxx的明文方式,所以不服务器段只需要使用类似title=request.getparameter('title')的方式就可以得到,用第一种方式得到的就是乱码
(3)如果在from中以post的方式传送一些值,而传送到url本身是明文的,如'gn.jsp/title=XXX'中其中,url的内容传送方式遵循(2),form内的值遵循(1)
问题:
服务器端并不知道客户段使用的什么编码方式,所以造成一种现象;无论是否使用iso-8859到gb2312的转换都造成有时好使有时不好使的结果。
解决方法;
在客户端,将(2)中的url进行编码,编码方式参见vbscript.vs,以及worktool.aspx.cs中的代码
疑惑;
在java中提供了java.net.URLEncoder.encode(value),在.net中都提供了类似System.Web.HttpUtility.UrlPathEncode(url),System.Web.HttpUtility.UrlEncode(mytest),但是在服务器端却接受不了,为什么????.
c#代码(服务器端处理url)
public static string URLEncoding(string vstrin)
{
string strreturn=""; for(int i=0;i<vstrin.Length ;i++)
{
if(Math.Abs((short)(vstrin[i])) < 0xff)
{
strreturn = s

# re: HTTP-GET和HTTP-POST

1/14/2005 6:51 PM by 欣禧博客
Here's a function that will decode URLEncoding. (If you are looking for an HTML
Decoding function - you are on your own.)

Function URLDecode(url)
temp = Replace(url,"+"," ",1,-1,1)
x = InStr(temp,"%")
Do While x > 0
URLDecode = URLDecode & Left(temp,x-1)
URLDecode = URLDecode & Chr(CLng("&H" & Mid(temp,x+1,2)))
temp = Mid(temp,x+3)
x = InStr(temp,"%")
Loop
URLDecode = URLDecode + temp
End Function

Note: This is modified version of code I stole from some ASP help site. My version of
ASP uses '+' for spaces versus %20. Hence the first Replace line. You should not have
to change this if your URLEncoding uses %20.

# re: HTTP-GET和HTTP-POST

3/2/2005 3:17 PM by A. C.
把空格转换为%20也行吧,不一定非要变成+(加号)。
<a herf=http://www.google.com/>www.google.com</a>

# re: HTTP-GET和HTTP-POST

8/31/2005 10:40 PM by SDF
SF

# re: HTTP-GET和HTTP-POST

5/4/2007 4:07 PM by test
test

# re: HTTP-GET和HTTP-POST

7/28/2007 2:18 PM by testName
good

Post Comment

Title  
Name  
Url
Comment   
Protected by Clearscreen.SharpHIPEnter the code you see: