【发布时间】:2012-09-12 05:11:35
【问题描述】:
以下代码不起作用:
using System;
using System.IO;
using System.Net;
using System.Web;
namespace Proyecto_Prueba_04
{
class Program
{
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string GetWebText(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.UserAgent = "A .NET Web Crawler";
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string htmlText = reader.ReadToEnd();
return htmlText;
} // End of the GetWebText method.
/// <summary>
///
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
string urlPrueba = Uri.UnescapeDataString("http://?????????.??/");
Console.WriteLine("urlPrueba" + " = " + urlPrueba);
var encoded = HttpUtility.UrlPathEncode(urlPrueba);
Console.WriteLine("encoded" + " = " + encoded);
string codigoHTML = GetWebText(encoded);
Console.WriteLine("codigoHTML" + " = " + codigoHTML);
Console.ReadLine();
} // End of the Main method.
} // End of the Program class.
} // End of the Proyecto_Prueba_04 namespace.
我不明白我必须如何处理 UNICODE URL。
有什么想法吗?
谢谢。
【问题讨论】:
-
您在此处看到的 URL 为 ????是一个俄语 URL,是这个:президент.рф
-
如果您的平台不能为您处理,您需要转换为 IDNA Punycode。但是,如果您的源文件不包含采用合理编码的 URL,那么当然不会有任何效果。
标签: c# unicode web-crawler idn