【问题标题】:Why isn't my intellisense listing HttpWebRequest.GetResponse method?为什么我的智能感知没有列出 HttpWebRequest.GetResponse 方法?
【发布时间】:2012-02-15 05:44:33
【问题描述】:
using System;
using System.Net;
using System.Xml.Linq;


namespace PhoneApp1
{
    public class ABC
    {
        //constructor

        public ABC()
        {


        }

        void abc()
        {
            String url = "";

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse resp = (HttpWebResponse)req.GetRepsonse(); //why a wiggly line here?
            XDocument Xmldoc = XDocument.Load(url);
        }

我没有得到 GetResponse()req 对象。为什么会这样?

这个link 和许多链接说它应该是可能的。

【问题讨论】:

  • 您的命名空间是否称为PhoneApp1,因为您在Windows Phone 上进行开发?如果是这样,请将 TAG 添加到您的问题中。
  • 添加了windows-phone-7标签。

标签: c# windows-phone-7 httpwebrequest getresponse


【解决方案1】:

鉴于您的命名空间,我假设您正在编写一个 Windows Phone 7 应用程序。 (在问题中明确说明这一点会很有帮助。)Windows Phone 7 开发使用 Silverlight,它不支持像 GetResponse 这样的同步操作。您应该查看Silverlight version of MSDN for HttpWebRequest,并寻找旁边有电话图标的成员。请注意,如果您点击该链接,您不会找到GetResponse 方法。您必须调用BeginGetResponse 并异步处理它。

(随着新的异步工作被放入 C# 5,这一切都会变得容易得多。)

【讨论】:

  • 是的,我正在使用 Windows 手机。它现在标记。谢谢
  • 嗨 Jon,你能告诉我们为什么需要为 windows phone 应用程序异步处理这个事情吗?为什么不允许正常的同步操作?
  • @nawfal:因为人们会尝试从 UI 线程执行此操作,并锁定 UI。异步操作也将成为 Windows 8 Metro 应用程序的标准。
猜你喜欢
  • 2013-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
相关资源
最近更新 更多