0
我想知道是否可以使用HttpWebRequest填充MVC模型?我正在嘗試構建一個MVC 4應用程序,我從大學課程列表頁面獲取數據,並在View中按幾種不同的方式進行按摩。我已經看到的例子都採取了響應流,並返回一個字符串或沒有被格式化爲MVC(使用console.write)。另外,據我瞭解,返回的數據不是JSON或XML格式。這是我的控制器迄今...可以使用HttpWebRequest填充模型嗎?
public ActionResult Index()
{
string postData = "semester=20143Fall+2013+++++++++++++++++++++++++++++++&courseid=&subject=IT++INFORMATION+TECHNOLOGY&college=&campus=1%2C2%2C3%2C4%2C5%2C6%2C7%2C9%2CA%2CB%2CC%2CI%2CL%2CM%2CN%2CP%2CQ%2CR%2CS%2CT%2CW%2CU%2CV%2CX%2CZ&courselevel=&coursenum=&startTime=0600&endTime=2359&days=ALL&All=All+Sections";
byte[] dataArray = Encoding.UTF8.GetBytes (postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www3.mnsu.edu/courses/selectform.asp");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = dataArray.Length;
using (WebResponse response = myRequest.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
//insert into a model? Maybe?
}
}
return View();
}
如果HttbWebRequest不能使用,有沒有辦法可以工作?還是我完全朝着錯誤的方向前進?