[英]c# is WebRequest.Create gives me a URL encoded?
I have been giving an API to send SMS, the API states that I should use this url 我一直在给一个API发送短信,该API指出我应该使用此网址
http://<server>:<port>/bulksms/bulksms?
username=XXXX&password=YYYYY&type=Y&dlr=Z&destination=QQQQQQQQQ&sour
ce=RRRR&message=SSSSSSSS<&url=KKKK>
Where message and url must be URL-UTF-8 encoded . 其中message和url必须是URL-UTF-8编码的 。
what I did is creating that url like this: 我所做的是像这样创建该网址:
string urlSMS = string.Format("http://{0}:{1}/bulksms/bulksms?username={2}&password={3}&type={4}&dlr={5}&destination={6}&source={7}&message={8}&url=0",
server, port, username, password, type, dlr, destination, source, message);
then I called that URL like this: 然后我这样称呼该URL:
WebRequest wr = WebRequest.Create(urlSMS);
wr.Timeout = 3500;
try
{
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
however, I kept having timeout error message, I checked everything that is why i am asking. 但是,我一直收到超时错误消息,我检查了所有这就是为什么我要问的问题。 i need to know if 我需要知道
WebRequest.Create(urlSMS)
gives me a URL-UTF-8
encoded or not. 给我一个URL-UTF-8
编码与否。
Thanks 谢谢
Yes. 是。 It looks like WebRequest.Create(url) will UTF-8 encode the url. 看起来WebRequest.Create(url)将对URL进行UTF-8编码。
When I try this: 当我尝试这个:
WebRequest r = WebRequest.Create("http://www.google.com/search?q=♥");
I can see that the internal representation if the URI is encoded: r.RequestUri.AbsoluteUri
returns http://www.google.com/search?q=%E2%99%A5
我可以看到内部表示形式(如果URI进行了编码): r.RequestUri.AbsoluteUri
返回http://www.google.com/search?q=%E2%99%A5
Whereas r.RequestUri.ToString()
returns http://www.google.com/search?q=♥
. r.RequestUri.ToString()
返回http://www.google.com/search?q=♥
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.