我試圖發送一個使用POST請求base64編碼的數據,它包含「+」字符。當我發送請求時,「+」被替換爲「」(空格)。這裏去HttpWebRequest不發送+(加)字符
public string POST(string url, string query)
{
HttpWebRequest hwrq = CreateRequest(url);
hwrq.CookieContainer = Cookies;
hwrq.Method = "POST";
hwrq.ContentType = "application/x-www-form-urlencoded";
byte[] data = Encoding.Default.GetBytes(query);
hwrq.ContentLength = data.Length;
hwrq.GetRequestStream().Write(data, 0, data.Length);
using (HttpWebResponse hwrs = (HttpWebResponse)hwrq.GetResponse())
{
using (StreamReader sr = new StreamReader(hwrs.GetResponseStream()))
{
return sr.ReadToEnd().Trim();
}
}
}
public HttpWebRequest CreateRequest(string url)
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
Request.UserAgent = UserAgent;
Request.Accept = Accept;
Request.Headers.Add("Accept-Language", AcceptLang);
Request.AutomaticDecompression = DMethod;
return Request;
}
我一直在跟蹤「查詢」變量的代碼,它保持用「+」字符,但是當我看到嗅探器(查爾斯)的請求,該請求不被髮送「 +」。
比如我想送
< ...> ZXJ + ZZQ < ...>
和
< ...> ZXJ ZZQ < ...>
實際上是發送。
我在做什麼錯?
在此先感謝。
非常感謝你! – Cracker
適用於WPF 4.5應用程序,如魅力。 –