Question

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.

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top