문제

I'm using Visual Studio 2012 and playing around with Windows Phone 7.1 application development. This is a newly-created project.

When I use this code, why do I get this error?

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

Code:

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;
}

...

It seems like it can't recognise that WebRequestMethods is a part of System.Net. It also fails if I specify System.Net.WebRequestMethods.Http.Post.

도움이 되었습니까?

해결책

System.Net.WebRequestMethods.Http isn't available in the .NET Profile for Windows Phone, though it may not be readily apparent depending on which documentation page you're looking at. Just set it to the string value "POST".

I have some additional context in my blog article: Windows Runtime-What's supported Where?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top