0

我正在使用 Visual Studio 和 Windows Phone 7 开发智能手机 FTP 客户端

我面临一些错误,例如

request.Method = WebRequestMethods.ftp.ListDirectory

错误 1 ​​目标平台不支持后期绑定。C:\Users\Zaheer\Documents\Visual Studio 2010\Projects\PhoneApp4\PhoneApp4\MainPage.xaml.vb 36 30 PhoneApp4

response = CType(request.GetWebResponse(), WebResponse) 错误 2 'GetWebResponse' 不是 'System.Net.WebRequest' 的成员。C:\Users\Zaheer\Documents\Visual Studio 2010\Projects\PhoneApp4\PhoneApp4\MainPage.xaml.vb 37 30 PhoneApp4

这是完整的代码,请帮助我

    Dim Request As WebRequest = Nothing
    Dim Response As WebResponse = Nothing
        Dim reader As StreamReader = Nothing
        Dim Port As Integer = 21
        Try
        Request = CType(WebRequest.Create(URL), WebRequest)
            Request.Method = "List"

        Request.Credentials = New NetworkCredential(Username, Password)
        Request.Method = WebRequestMethods.Ftp.ListDirectory
        Response = CType(Response.GetWebRequest(), WebResponse)
            reader = New StreamReader(Response.GetResponseStream())
            While (reader.Peek() > -1)
                RemoteSite.Items.Add(reader.ReadLine())
            End While
        Catch ex As Exception
            Console.WriteLine("List Sucessfully.")
        End Try
    End Sub
4

1 回答 1

2

对于后期绑定错误,您需要将您尝试设置的对象转换为正确的数据类型,因为 WP7 不支持类型的运行时评估(后期绑定)。

至于错误GetWebResponse,编译器是绝对正确的,WebRequest(甚至HttpWebRequest)没有GetWebResponse方法,也许您正在寻找WebRequest.GetResponse

例如:

response = request.GetResponse(); // where request is of type WebRequest or a derived class
于 2013-07-01T11:04:56.110 回答