【问题标题】:Why does WebRequestMethods not exist in the current context?为什么当前上下文中不存在 WebRequestMethods?
【发布时间】:2013-01-13 04:07:06
【问题描述】:

我正在使用 Visual Studio 2012 并在玩 Windows Phone 7.1 应用程序开发。这是一个新创建的项目。

当我使用此代码时,为什么会出现此错误?

The name 'WebRequestMethods' does not exist in the current context

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

...

public MainPage() {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
    request.Method = WebRequestMethods.Http.Post;
}

...

它似乎无法识别 WebRequestMethods 是 System.Net 的一部分。如果我指定 System.Net.WebRequestMethods.Http.Post,它也会失败。

【问题讨论】:

    标签: c# windows-phone-7 visual-studio-2012 windows-phone-8 system.net


    【解决方案1】:

    System.Net.WebRequestMethods.Http 在 Windows Phone 的 .NET 配置文件中不可用,但根据您正在查看的文档页面,它可能并不明显。只需将其设置为字符串值“POST”即可。

    我的博客文章中有一些额外的上下文:Windows Runtime-What's supported Where?

    【讨论】:

    • 我怀疑是这样的,但我找不到任何相关信息。谢谢!
    猜你喜欢
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2019-08-05
    • 2020-07-31
    • 2021-01-16
    • 1970-01-01
    相关资源
    最近更新 更多