Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我们是否需要在使用HttpWebRequest获取URL之前对其进行编码_C#_Httpwebrequest_Webrequest_Url Encoding_Urldecode - Fatal编程技术网

C# 我们是否需要在使用HttpWebRequest获取URL之前对其进行编码

C# 我们是否需要在使用HttpWebRequest获取URL之前对其进行编码,c#,httpwebrequest,webrequest,url-encoding,urldecode,C#,Httpwebrequest,Webrequest,Url Encoding,Urldecode,我正在将URL解码为浏览器显示的最纯粹的形式,然后使用 我的问题是,我还用 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(srRelativeUrl); 是否有任何情况会因为url未正确编码而导致错误 答案非常重要当您遇到无效url时,它将生成错误消息。因此,如果url格式不正确,则很可能会出现异常 因此,您可以添加以下内容: try { HttpWebRequest postReq = (HttpWebRe

我正在将URL解码为浏览器显示的最纯粹的形式,然后使用

我的问题是,我还用

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(srRelativeUrl);
是否有任何情况会因为url未正确编码而导致错误


答案非常重要

当您遇到无效url时,它将生成错误消息。因此,如果url格式不正确,则很可能会出现异常

因此,您可以添加以下内容:

try
   {
    HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create(url);
    ....res of your code.....
   }
catch (WebException p)
        {
            //You can record these errors in maybe database and later review them.
        }

Ty作为答案,我已经在做了,但我问的不同:D对不起,英语不是我的母语:),你愿意解释一下吗?只要读一下标题,我们不需要对它们进行编码就可以使用HttpWebRequest运行。
try
   {
    HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create(url);
    ....res of your code.....
   }
catch (WebException p)
        {
            //You can record these errors in maybe database and later review them.
        }