c# is WebRequest.Create gives me a URL encoded?

流过昼夜 提交于 2020-01-05 13:07:17

问题


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>

Where message and url must be URL-UTF-8 encoded.

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:

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.

Thanks


回答1:


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

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

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



来源:https://stackoverflow.com/questions/30481939/c-sharp-is-webrequest-create-gives-me-a-url-encoded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!