[英]HttpFormUrlEncodedContent not part of system.Net.Http
我在我的應用程序中使用HttpFormUrlEncodedContent
對象進行PostAsync
。 我把所有必要的參考作為:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
以下是我的帖子的代碼:
var client = new HttpClient();
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("task", task));
values.Add(new KeyValuePair<string, string>("merchant", "2234-6566"));
values.Add(new KeyValuePair<string, string>("ref", refl));
values.Add(new KeyValuePair<string, string>("hash", hash));
values.Add(new KeyValuePair<string, string>("amount", "20"));
values.Add(new KeyValuePair<string, string>("seller", "mymail@mail.com"));
values.Add(new KeyValuePair<string, string>("remarks", "payment"));
HttpFormUrlEncodedContent formContent = new HttpFormUrlEncodedContent(values);
var content = new FormUrlEncodedContent(values);
Task<HttpResponseMessage> t = client.PostAsync("https://epay.com/api/", content);
t.Wait();
var response = t.Result;
有了這個,我得到如下錯誤信息:
找不到類型或命名空間名稱'HttpFormUrlEncodedContent'(您是否缺少using指令或程序集引用?)
可能有什么方法可以解決這個問題?
這是因為HttpFormUrlEncodedContent Class來自Windows.Web.Http
命名空間,用於UWP應用程序。
因此,如果您的程序實際上是UWP應用程序,那么請確保引用了所需的程序集並為該命名空間添加using
。
否則只需將值集合添加到FormUrlEncodedContent構造函數中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.