C#是WebRequest.Create给我的URL编码吗? [英] c# is WebRequest.Create gives me a URL encoded?

查看:177
本文介绍了C#是WebRequest.Create给我的URL编码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在提供一个用于发送SMS的API,该API指出我应该使用此url

I have been giving an API to send SMS, the API states that I should use this url

http://<server>:<port>/bulksms/bulksms?
username=XXXX&password=YYYYY&type=Y&dlr=Z&destination=QQQQQQQQQ&sour
ce=RRRR&message=SSSSSSSS<&url=KKKK>

消息 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);

然后我这样称呼该URL:

then I called that URL like this:

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)

是否给我一个URL-UTF-8编码.

谢谢

推荐答案

是.看起来WebRequest.Create(url)将对URL进行UTF-8编码.

Yes. It looks like WebRequest.Create(url) will UTF-8 encode the url.

当我尝试此操作时:

WebRequest r = WebRequest.Create("http://www.google.com/search?q=♥");

如果URI编码,我可以看到内部表示形式:r.RequestUri.AbsoluteUri返回http://www.google.com/search?q=%E2%99%A5

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

r.RequestUri.ToString()返回http://www.google.com/search?q=♥.

这篇关于C#是WebRequest.Create给我的URL编码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆