0
我似乎無法得到我的HTTP POST方法的掛起。我剛剛學會了如何做GET方法來檢索網頁,但現在我試圖填寫網頁上的信息,似乎無法讓它工作。這回來的源代碼始終是一個無效的頁面(完全破碎的圖像/不正確的信息)帶JSON的HTTP帖子
public static void jsonPOST(string url)
{
url = "http://treasurer.maricopa.gov/Parcel/TaxReceipt.aspx/GetTaxReceipt";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Accept = "application/json, text/javascript, */*; q=0.01";
httpWebRequest.Headers.Add("Accept-Encoding: gzip, deflate");
httpWebRequest.CookieContainer = cookieJar;
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("Accept-Language: en-US,en;q=0.5");
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW65; Trident/7.0; MAM5; rv:11.0) like Gecko";
httpWebRequest.Referer = "http://treasurer.maricopa.gov/Parcel/TaxReceipt.aspx";
string postData = "{\"startDate\":\"1/1/2013\",\"parcelNumber\":\"17609419\"}";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData);
httpWebRequest.ContentLength = bytes.Length;
System.IO.Stream os = httpWebRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = httpWebRequest.GetResponse();
if (resp == null)
{
Console.WriteLine("null");
}
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string source = sr.ReadToEnd().Trim();
}
編輯:我更新的代碼,以反映我的新的問題。我現在的問題是,源代碼不是回到我身上的東西。我正在獲取source
中的原始JSON信息。我可以用它來反序列化我需要獲取的信息,但我很好奇爲什麼實際的源代碼不會回到我的身邊
這是ASP.NET MVC還是WebForms? – valverij
這是一個控制檯應用程序,我試圖只爲我們的公司數據庫的一些信息刮 – MaylorTaylor