0

我正在开发 Windows 8 应用程序。当我尝试执行代码时,Visual Studio 2012 中出现错误消息“命名空间 'System.Net.Http' 中不存在类型或命名空间名称 'Post'(您是否缺少程序集引用?)”

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

代码来自 URL .NET:Simplest way to send POST with data and read response

. 任何帮助表示赞赏。

4

2 回答 2

4

将命名空间添加System.Net.Http.HttpMethod到您的代码中。

于 2013-02-28T07:30:27.260 回答
1

使用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)
{}
于 2013-02-28T09:57:08.690 回答