Unable to cast object of type 'System.Net.HttpWebRequest' type 'System.Net.FileWebRequest'

Ich versuchen, die Datei vom server herunterladen, mit FileWebRequest. Aber ich bekomme Fehler:

Methode, die auf dem download ist hier:

public string HttpFileGetReq(Uri uri, int reqTimeout, Encoding encoding)
{
    try
    {
        string stringResponse;
        var req = (FileWebRequest)WebRequest.Create(uri);
        req.Timeout = reqTimeout;
        req.Method = WebRequestMethods.File.DownloadFile;

        var res = (FileWebResponse)req.GetResponse();

        //using (var receiveStream = res.GetResponseStream())
        //using (var readStream = new StreamReader(receiveStream,encoding))
        //{
        //   stringResponse = readStream.ReadToEnd();
        //}

        return stringResponse="0K";
    }
    catch (WebException webException)
    {
        throw webException;
    }
}

Nutzung ist hier:

public dynamic LoadRoomMsg(IAccount account, string roomId)
{
    try
    {
        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);

        var htmlStringResult = HttpFileGetReq(new Uri(uri), ReqTimeout, EncodingType);

        //var htmlStringResult = _httpReq.HttpGetReq(new Uri(string.Format("{0}{1}?{2}&lok=", PokecUrl.RoomMsg,account.SessionId,roomId)),
        //   ReqTimeout, account.Cookies, EncodingType);
        if (!string.IsNullOrEmpty(htmlStringResult))
        {
            return true;
        }
        return false;
    }
    catch (Exception exception)
    {
        throw exception;
    }
}

URL auf die Datei ist hier.

Möchte ich Lesen Sie diese Datei in string-variable, das ist alles. Wenn jemand etwas Zeit und kann mir helfen, ich wäre sehr froh um ihn.

InformationsquelleAutor | 2011-01-21

Schreibe einen Kommentar