我要访问的URL为:www.dianping.com/search/m/2/10/或者http://www.dianping.com/search/m/1/10/ 其中2代表北京。1代表上海。
然后我要提取HttpWebResponse的内容。
我写的代码为如下:
private string DefaultIP = "www.dianping.com/search/m/2/10/";
   // private string DefaultUrl = "/PublicCode_Voice/EditTask/External_Confer_Post.asp?";    protected void Page_Load(object sender, EventArgs e)
    {        Encoding encoding = Encoding.GetEncoding("Unicode");
        string strUrl = @"http://" + DefaultIP;
        string postData="" ;//= "username=" + UserName + "&password=" + password + "&area_c=&telfile1=" + TelePhones + "";
        byte[] data = encoding.GetBytes(postData);
        // 准备HTTP请求...
        System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = data.Length;
        System.IO.Stream newStream = myRequest.GetRequestStream();
        // 发送数据...
        newStream.Write(data, 0, data.Length);
        newStream.Close();
        //HTTP响应...
        System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
        System.IO.Stream receiveStream = myResponse.GetResponseStream();
        Encoding encode = System.Text.Encoding.GetEncoding("Unicode");
        System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode);
        Char[] read = new Char[256];
        int count = readStream.Read(read, 0, 256);
        StringBuilder sb = new StringBuilder("");
        while (count > 0)
        {
            String readstr = new String(read, 0, count);
            sb.Append(readstr);
            count = readStream.Read(read, 0, 256);
        }
        myResponse.Close();
        readStream.Close();
        this.Label1.Text= sb.ToString();
    }
}
他们说是通过Get方法来得到的。我现在用的Post方法。最后显示的是乱码。我也把Encoding encode = System.Text.Encoding.GetEncoding("Unicode");他变成Encoding encode = System.Text.Encoding.GetEncoding("gb2312")还是乱码。是我的思路就错吗?请高手指点。最好能给代码看看。

解决方案 »

  1.   

    To: meixiaofeng(yesmsn)能给解释解释吗?怎么改。谢谢。====CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2
      

  2.   

    发贴目的:
    1。顶贴。
    2。乱码问题还没解决。
    3。url为:http://www.dianping.com/search/m/1/10/本帮&d=c1&pg=2其中 1/与10/还有本帮都是我选择页面控件后传过去的。直接转到对应的url上面。 最后面的&d=c1&pg=2这两个也是。最后一个表示第几页。请问这个访问方式是不是即有Get方式也有Post方式。请给我解释两个方式的区别。4。就是我上面贴出的代码。大家帮忙给看看。我再做什么修改。就能Request 和Response都能成功。并解决乱吗的问题。
    4。表示对斑竹等高手的有点意见。怎么这样不关心弟兄们了。有点说不下去。
    5。仅此而已
      

  3.   

    乱码问题基本上是因为编码转化不当造成的,楼主可以统一使用utf8试一下
      

  4.   

    楼主可以到msdn网站搜索HttpWebRequest,看看范例
      

  5.   

    TO:jeremychen001181(青竹竿) 能给一个连接吗?我这里找了半天也没找到。
    ====CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2