我认为您有两个选择:
第一个选项是使用AJAX在客户端执行此操作:((http://api.jquery.com/jquery.ajax/
代码看起来像:
function CallOtherSite(otherSiteUrl) {
$.ajax({
url: otherSiteUrl,
cache: false,
success: function (html) {
//This will be the html from the other site
//parse the html/xml and do what you need with it.
}
});
因为这是在客户端使用JavaScript完成的,因此您很可能会遇到CORS的问题。 ((http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-cors-support-in-asp-net-asp-net-web-apis.aspx)
我认为的另一个选项和更好的选择是在服务器端执行此操作。 (在控制器或带有剃须刀的视图中)(在调发器中会容易得多...)
try
{
var request = (HttpWebRequest)WebRequest.Create(urlToOtherSite);
request.Accept = "application/xml";
request.Method = "GET";
webResponse = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream());
string responseText = sr.ReadToEnd();
}
catch(Exception ex)
{
}
finally
{
if (sr != null) { sr.Close(); }
if (webResponse != null) { webResponse.Close(); }
}
然后,您可以使用StreamReader获取HTML/XML,并按照它做。
希望这可以帮助...