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.

3
  • 1
    This code is too old, take advantage of new toy: HttpClient msdn.microsoft.com/en-us/library/… Commented Feb 28, 2013 at 7:26
  • Does it provide Post or equivalent functionality? Commented Feb 28, 2013 at 9:14
  • @Cuong Le Could u provide equivalent code of HttpClient for the above code? Commented Feb 28, 2013 at 9:42

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

getting error "Non-invocable member 'System.Net.Http.HttpMethod.Post' cannot be used like a method."
HttpMethod is an enumeration, not a method, so yes, you're getting this error because you're not using it correctly.
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)
{}

3 Comments

Could u be specific on how to get response from client.PostAsync("yourURI", content);
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?
I have raised a new question regarding this. stackoverflow.com/questions/15198936/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.