WebClient DownloadString问题

zhengzongwei 2010-07-09 02:56:17


有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.Net.WebException: 无法解析此远程名称: 'chongzuo.ganji.com'
在 System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
在 System.Net.WebClient.DownloadString(Uri address)
在 System.Net.WebClient.DownloadString(String address)
在 test.Form1.getPage(String url)
在 test.Form1.button1_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
test
程序集版本: 1.0.0.0
Win32 版本: 1.0.0.0
基本代码: file:///E:/项目/测试/test/test/bin/Debug/test.exe
----------------------------------------
System.Windows.Forms
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.resources
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.resources.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。





/// <summary>
/// 根绝URL获取信息
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string getPage(String url)
{

WebClient wc = new WebClient();
try
{
wc.Encoding = Encoding.GetEncoding("utf-8");

//string u = Convert.ToString(url);
string t = wc.DownloadString(url);
return t;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
throw;
}



wc.Dispose();



}




private void button1_Click(object sender, EventArgs e)
{
city c = new city();
DataTable dt = c.GetList(" ");
for (int a = 0; a < dt.Rows.Count; a++)
{
//this.textBox2.Text += dt.Rows[i]["cityPinyin"].ToString();

//}
string aa = getPage("http://" + dt.Rows[a]["cityPinyin"].ToString() + ".ganji.com/fang1/");
string resultString = null;
String [] bb = new String[100];
try
{
resultString = Regex.Match(aa, "<dt>区域:</dt>.*?</dl>", RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline).Value;

Regex _regxe = new Regex(@"(?<=""/).*?(?=</)");
MatchCollection match = _regxe.Matches(resultString);
for (int i = 0; i < match.Count; i++)
{
bb[i] = match[i].Value;
Match m = Regex.Match(bb[i], @"/(\w+)/"">(((?!其他).)+)");
string s1 = m.Groups[1].Value;
string s2 = m.Groups[2].Value;

this.textBox2.Text += s1;
this.textBox2.Text += s2 + "==============";

//cityArea _cityArea = new cityArea();
//_cityArea.cityAreaPinyin = s1;
//_cityArea.cityarea = s2;
//_cityArea.cityID = int.Parse(dt.Rows[a]["id"].ToString());
//_cityArea.Add();
}


}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}

}

}



哪位高手帮忙看看这是什么问题怎么解决吖
...全文
503 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LutzMark 2010-07-09
  • 打赏
  • 举报
回复
string aa = getPage("http://chongzuo.ganji.com/fang1/");
我这里没问题,可以获取页面数据


你跟踪调试下dt.Rows[a]["cityPinyin"].ToString() 的值
wuyq11 2010-07-09
  • 打赏
  • 举报
回复
访问这个网址是否有问题
zhengzongwei 2010-07-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yuxuanji 的回复:]
代码没问题,看异常信息:System.Net.WebException: 无法解析此远程名称: 'chongzuo.ganji.com'
多半是你的url没加http吧

C# code
url="http://chongzuo.ganji.com/"
[/Quote]

不是吖..
string aa = getPage("http://" + dt.Rows[a]["cityPinyin"].ToString() + ".ganji.com/fang1/");

那个URL是从这里来的
LutzMark 2010-07-09
  • 打赏
  • 举报
回复
代码没问题,看异常信息:System.Net.WebException: 无法解析此远程名称: 'chongzuo.ganji.com'
多半是你的url没加http吧
url="http://chongzuo.ganji.com/"

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧