Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 2.25 KB  |  hits: 49  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FileWebRequest'
  2. public string HttpFileGetReq(Uri uri, int reqTimeout, Encoding encoding)
  3. {
  4.     try
  5.     {
  6.         string stringResponse;
  7.         var req = (FileWebRequest)WebRequest.Create(uri);
  8.         req.Timeout = reqTimeout;
  9.         req.Method = WebRequestMethods.File.DownloadFile;
  10.  
  11.         var res = (FileWebResponse)req.GetResponse();
  12.  
  13.         //using (var receiveStream = res.GetResponseStream())
  14.         //using (var readStream = new StreamReader(receiveStream,encoding))
  15.         //{
  16.         //    stringResponse = readStream.ReadToEnd();
  17.         //}
  18.  
  19.         return stringResponse="0K";
  20.     }
  21.     catch (WebException webException)
  22.     {
  23.         throw webException;
  24.     }
  25. }
  26.        
  27. public dynamic LoadRoomMsg(IAccount account, string roomId)
  28. {
  29.     try
  30.     {
  31.         string uri = string.Format("http://www-pokec.azet.sk/_s/chat/nacitajPrispevky.php?{0}&lok={1}&lastMsg=0&pub=0&prv=0&r=1295633087203&changeroom=1" , account.SessionId, roomId);
  32.  
  33.         var htmlStringResult = HttpFileGetReq(new Uri(uri), ReqTimeout, EncodingType);
  34.  
  35.         //var htmlStringResult = _httpReq.HttpGetReq(new Uri(string.Format("{0}{1}?{2}&lok=", PokecUrl.RoomMsg,account.SessionId,roomId)),
  36.         //    ReqTimeout, account.Cookies, EncodingType);
  37.         if (!string.IsNullOrEmpty(htmlStringResult))
  38.         {
  39.             return true;
  40.         }
  41.         return false;
  42.     }
  43.     catch (Exception exception)
  44.     {
  45.         throw exception;
  46.     }
  47. }
  48.        
  49. public string HttpFileGetReq(Uri uri, int reqTimeout, Encoding encoding)
  50. {
  51.     string stringResponse;
  52.     var req = (HttpWebRequest)WebRequest.Create(uri);
  53.  
  54.     req.Timeout = reqTimeout;
  55.  
  56.     var res = (HttpWebResponse)req.GetResponse();
  57.  
  58.     using (var receiveStream = res.GetResponseStream())
  59.     {
  60.         using (var readStream = new StreamReader(receiveStream,encoding))
  61.         {
  62.             return readStream.ReadToEnd();
  63.         }
  64.     }
  65. }
  66.        
  67. string uri = string.Format(
  68.     "http://www-pokec.azet.sk/_s/chat/nacitajPrispevky.php?{0}&lok={1}&lastMsg=0&pub=0&prv=0&r=1295633087203&changeroom=1",
  69.     account.SessionId,
  70.     roomId);
  71.  
  72. System.Net.WebClient wc = new System.Net.WebClient();
  73. string webData = wc.DownloadString(uri);
  74.  
  75. ...parse the webdata response here...
  76.        
  77. {"reason":0}