使用 HttpWebRequest 发布非英语数据
该网站采用希伯来语,编码为 Windows-1255。 使用 Firefox 的 Tamer Data 扩展,我看到 Post 参数之一是:
+++++++++%E4%FA%E7%E1%F8+++++++++
使用 此 表我将其翻译为希伯来语:
++++ +++++התחבר+++++++++
现在,我想将其作为发布数据发送:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
string param =;// What should I set here? should i type in hebrew? should i conver it to hex?
//Should I type +++++++++%E4%FA%E7%E1%F8+++++++++ or maybe %E4%FA%E7%E1%F8?
string postData = string.Format({0}={1}",param,value);
byte[] byteArray = Encoding.UTF8.GetBytes(postData); //what encoding to use?
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
The web site is in hebrew with Windows-1255 encoding.
Using Firefox's Tamer Data extension, i see that one of the Post parameters is:
+++++++++%E4%FA%E7%E1%F8+++++++++
using this table I translated it to hebrew:
+++++++++התחבר+++++++++
Now, I want to send it as post data:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
string param =;// What should I set here? should i type in hebrew? should i conver it to hex?
//Should I type +++++++++%E4%FA%E7%E1%F8+++++++++ or maybe %E4%FA%E7%E1%F8?
string postData = string.Format({0}={1}",param,value);
byte[] byteArray = Encoding.UTF8.GetBytes(postData); //what encoding to use?
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为最安全的方法是用希伯来语输入它,并使用
Uri.EscapeDataString(paramValue) 转义字符
因此在这种情况下,使用 ASCII 是安全的。
Safest way in my opinion is type it in hebrew, and use
Uri.EscapeDataString(paramValue)
to escape the charactersSo in this case, it would be safe to use ASCII.
如果您使用内容类型
"application/x-www-form-urlencoded"
,则必须以 URL 形式对参数进行编码(即 URL 中无效的每个字节都必须是%
+ 十六进制代码)。顺便说一句,+
在解码过程中变成了空格。要获取
byteArray
,请使用ASCII
编码(该数组中的所有字符都将具有一个代码点 <128)。在这种情况下,UTF-8
也可以工作,因为在这个范围内,它们匹配,但它不符合您的意图。If you use the content type
"application/x-www-form-urlencoded"
, then you must encode the parameters in URL form (i.e. every byte that's not valid in a URL must be%
+ the hex code). The+
becomes a space during decoding, btw.To get the
byteArray
, useASCII
encoding (all characters in that array will have a code point < 128). In this case,UTF-8
would also work because in this range, they match, but it would not should your intention.@dan你是对的,
它的效果很好
@dan you are correct,
its works very well