0

I am developing Windows 8 app. Error message "The type or namespace name 'Post' does not exist in the namespace 'System.Net.Http' (are you missing an assembly reference?)" is coming in Visual Studio 2012 when I try to execute the code

byte[] response = System.Net.Http.Post
  (
      url: "someurl",
      contentType: "application/json",
      contentLength: 32,
      content: "pqpUserName=admin&password=test@123"
  );

The code is from the URL .NET: Simplest way to send POST with data and read response

. Any help is appreciated.

Community
  • 1
  • 1
Ramesh
  • 392
  • 1
  • 12
  • 39

2 Answers2

4

Add the System.Net.Http.HttpMethod namespace to your code.

Herks
  • 897
  • 9
  • 25
1

Use HttpClient:

var client = new HttpClient();

var pairs = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("pqpUserName", "admin"),
                    new KeyValuePair<string, string>("password", "test@123")
                };

var content = new FormUrlEncodedContent(pairs);

var response = client.PostAsync("yourURI", content).Result;

if (response.IsSuccessStatusCode)
{}
cuongle
  • 74,024
  • 28
  • 151
  • 206
  • Could u be specific on how to get response from client.PostAsync("yourURI", content); – Ramesh Feb 28 '13 at 10:11
  • Hey, The above code is working in Windows store app. But, HttpClient is not available in Windows Phone SDK. Any idea about the equivalent code for the above code in Windows Phone SDK 8.0? – Ramesh Mar 04 '13 at 10:09
  • I have raised a new question regarding this. http://stackoverflow.com/questions/15198936/windows-phone-sdk-post-request – Ramesh Mar 04 '13 at 10:28