1. make sure to check the Status property2. maybe you should specify a request header? seehttp://www.thecodeproject.com/csharp/httpmail.aspalso, please, don't use XMLHTTP in .NET, you could use HttpWebRequest/HttpWebResponse classes in System.Net and classes in System.Xml, see(unfortunately it is in VB):
http://www.codeproject.com/useritems/ExDAV.aspalso see
http://groups.google.com/groups?q=PROPFIND+httpwebrequest&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ClUpP5clCHA.1672%40cpmsftngxa08&rnum=2if it needs authentication, you could do
request.Credentials = new  NetworkCredential("UserName","Password");
....

解决方案 »

  1.   

    思归:
    谢谢你的帮助,其实以前(应该说是2个月以前)我也问过你类似的问题,当时你就提醒我不要用XMLHTTP在.NET,可是我怕麻烦,贪图方便执意用XMLHTTP,后来莫名其妙的程序就通了,达到我想要的效果了。2个月后,我再看这个程序的时候,又莫名其妙的不通了,现在时间也快没有了,我必须尽快做出来,唉,真有点后悔当初没有听你的劝告呀。现在我觉得用HttpWebRequest/HttpWebResponse 来做,其中你提到
    if it needs authentication, you could do
    request.Credentials = new  NetworkCredential("UserName","Password");
    我在程序中也加上了这一段代码,可是我发现这段代码好象没有起作用,在服务器要求我提供身份认证时,连接就断掉了,我并没有向服务器提供我的username,password,此时弹出一个对话框说出现了“未处理的‘System.Net.WebException'类型的异常出现在system.dll中
     其他信息:远程服务器返回错误:(401)未经授权。”那,我应该怎样加上我的身份认证?
      

  2.   

    are you using Windows Integration authentication? if yes, try
    request.Credentials= System.Net.CredentialCache.DefaultCredentials;if you are using a proxy, you might need to try something likeWebProxy wp = new WebProxy("http://proxy.intranet.ch:80", true);
    wp.Credentials = System.Net.CredentialCache.DefaultCredentials;
    request.Proxy = wp;
      

  3.   

    思归:
    我没有用Windows Integration authentication或者 a proxy呀。
    我的代码:
    string _username = "[email protected]";
    string _password = "1234567";
    string _serverUrl = "http://services.msn.com/svcs/hotmail/httpmail.asp";
    string folderQuery = null;
    folderQuery += "<?xml version='1.0'?><D:propfind xmlns:D='DAV:' ";
    folderQuery += "xmlns:h='http://schemas.microsoft.com/hotmail/' ";
    folderQuery += "xmlns:hm='urn:schemas:httpmail:'><D:prop>";
    folderQuery += "<<hm:inbox/><hm:sendmsg/>";
    folderQuery += "<hm:msgfolderroot/></D:prop></D:propfind>";HttpWebRequest request_ = (HttpWebRequest)WebRequest.Create(_serverUrl);

    request_.Method = "PROPFIND";
    request_.ContentType = "text/xml";
    request_.ContentLength = folderQuery.Length;
    request_.Expect = null;
    request_.UserAgent = "Outlook-Express/5.0 (MSIE 5.0; Windows 98; DigExt)";
    request_.KeepAlive = true;
    request_.Credentials = new NetworkCredential(_username,_password);request_.Headers.Add("Depth","0");
    request_.Headers.Add("Brief","t");
    StreamWriter writer_ = new StreamWriter(request_.GetRequestStream());
    writer_.Write(folderQuery);
    writer_.Close();HttpWebResponse response_ = (HttpWebResponse)request_.GetResponse();
    Console.WriteLine(new StreamReader(response_.GetResponseStream()).ReadToEnd());
    Console.ReadLine();
      

  4.   

    frankly, I have no ideaI tried your code and changed the username/password to mine, and I was getting the same errors. I tried similar code with ServerXMLHTTP in javascript, it was working, weird. I would suggest you to fall back to XmlHTTP for now. Also try ServerXMLHTTP instead of XMLHTTP
      

  5.   

    思归:
    不管怎么说,都非常谢谢你,你为我这个程序也花了不少时间。谢谢!
    我要做的是一个收发hotmail的邮件的代理,现在一直不能连接hotmail的服务器,真是让我寸步难行,我会继续努力找资料,尝试解决这个问题的。
    如果你什么时候有了什么想法,我希望你能提点我一下,不甚感激。:)
    网上有一篇关于用C#实现hotmail收发的文章,我最初就是利用他的代码来编程的。那篇文章我想你也看过。真不知道自己出错在哪里。呵呵。
      

  6.   

    here is what you do, get the project file fromhttp://www.csharphelp.com/archives2/archive456.htmlRemove the old MSXML2 reference and add a reference to MSXML4.dll, then do the following changes:EntryPoint.cs:string username = "Put Your Email Account Here";
    string password = "Put Your Password Here";MailClient.cs:xmlHttp_ = new XMLHTTP();
    ==>
    xmlHttp_ = new ServerXMLHTTP40();
    private XMLHTTP xmlHttp_ = null;
    ===>
    private ServerXMLHTTP40 xmlHttp_ = null;
      

  7.   

    思归:
         你好。
         我试过你说的那样修改了。可是如果用ServerXMLHTTP40 的话,在发送http包的时候,就不支持重定向了。
      

  8.   

    it supports redirection, only you don't have control, try WinHTTP COM component, then, :-)http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/http/winhttp_versions.asp
      

  9.   

    思归:
      你好。
      在XMLHTTP上纠缠了这么久,出了错误常常也找不到为什么。总觉的好多东西都在自己控制之外,它自动帮我完成的许多功能,如果其中出了什么差错,我也不知道该怎么办。
      所以,我想是不是用最原始的HTTP请求来做,自己完成每次重定向的过程,会不会好一点,至少那一步出问题也知道为什么。这是我的一个想法,我没有什么经验,不知道这个想法是否可行?我想知道你的看法。
      

  10.   

    sure, with HttpWebRequest/HttpWebResponse, you can set HttpWebRequest's AllowAutoRedirect property to false and check if there is a header named "Location"
      

  11.   

    思归:
        你好。
        我差不多做出了一半吧,我用HttpWebRequest/HttpWebResponse进行自己重定向,与服务器连接上了。在最后服务器发给我信息的时候,在包头还有很多Set-Cookie:字段,我需要把服务器给我的Cookie保存下来。
      
    我这样写
    CookieCollection myCookieCollection = HttpWResp_.Cookies;
    for (int i = 0; i < myCookieCollection.Count; i++)
    {
        Console.WriteLine(myCookieCollection[i]);
    }好象不对。我一个Cookie都没有得到。
      

  12.   

    我也来凑一下热闹:*.js
    var xml=new ActiveXObject("Msxml2.XMLHTTP");
    xml.open("POST",fileName+"?id="+textOrder.value,false);
    xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xml.send();
    alert(xml.responseText);
      

  13.   

    what is the output for 
    Console.WriteLine(myCookieCollection.Count);?if you still cannot get it, go through the Headers yourself instead of using Cookies, I have known .NET doesn't work well with cookies