Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpWebRequest错误-request.BeginGetResponse();_C#_Xaml_Windows Phone 8_Httpwebrequest - Fatal编程技术网

C# HttpWebRequest错误-request.BeginGetResponse();

C# HttpWebRequest错误-request.BeginGetResponse();,c#,xaml,windows-phone-8,httpwebrequest,C#,Xaml,Windows Phone 8,Httpwebrequest,我正在用C#/.xaml编写一个手机应用程序 我不想简单地将应用程序指向某个网站,而是想从某个特定网站获取某些信息。我也知道我想从中获取信息的类名 我有代码,但没有请求。BeginGetResponse();返回错误“方法没有重载”。我做错了什么 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Window

我正在用C#/.xaml编写一个手机应用程序

我不想简单地将应用程序指向某个网站,而是想从某个特定网站获取某些信息。我也知道我想从中获取信息的类名

我有代码,但没有请求。BeginGetResponse();返回错误“方法没有重载”。我做错了什么

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using GamesWithGold.Resources;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace MyIP
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
        class WebFetch
        {
            static void Main(string[] args)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com/");
                HttpWebResponse response = (HttpWebResponse)request.BeginGetResponse();

                StreamReader stream = new StreamReader(response.GetResponseStream());

                string final_response = stream.ReadToEnd();

                Regex r = new Regex(@"Your IP");
                Match m = r.Match(final_response);

                Console.WriteLine(final_response);
            }
        }
    }
}

我认为您只需要调用
GetResponse
,而不是
BeginGetResponse
BeginGetResponse
if用于异步调用
GetResponse
。您的代码应该如下所示:

  HttpWebResponse response = (HttpWebResponse)request.GetResponse();

该错误基本上意味着您在上述示例中使用的方法的签名与BeginGetResponse方法允许的签名不匹配。实现此方法的正确方法是传入回调和请求状态。回调将是您的处理程序,一旦请求返回响应,就会执行回调

请参阅以了解如何正确实施此方法