我正在使用代理文件来允许我们的系统使用ajax从我们系统的不同子域中加载页面。我第一次尝试就成功完成了这个任务,但是我的第二次尝试却给了我一个错误,而且我正在努力解决原因,希望能得到任何帮助。远程服务器返回错误:(404)未找到 - HttpWebResponse
首先这是我Proxy.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string proxyURL = HttpUtility.UrlDecode(Request.QueryString["u"]);
if (proxyURL != string.Empty)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(proxyURL);
request.Method = "POST";
request.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = response.ContentType;
Stream content = response.GetResponseStream();
if (content != null)
{
StreamReader contentReader = new StreamReader(content);
Response.ContentType = contentType;
Response.Write(contentReader.ReadToEnd());
}
}
}
}
我的HTML/JavaScript是只是这样的:
<script>
$(document).ready(function() {
$.ajax({
type: "POST",
url: "Proxy.aspx?u=<%=GetUrl()%>",
success: function (data) {
$('#iFrameHolder').html(data);
}
});
});
</script>
<div id="iFrameHolder"></div>
然后我使用getURL()函数来建立的网址无论我在子域上的项目需要什么页面。
我得到这个在所有的工作没有问题,一个网址,但第二次尝试,我收到此错误:
System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at G2F.Collective.WebApplication.Shared.Proxy.Page_Load(Object sender, EventArgs e)
in D:\My Documents\Firefly\Collective\Dev\Solution\WebSites\G2F.Collective.WebApplication\Shared\Proxy.aspx.cs:line 26
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
那对我会建议什么是错的我的网址正在建设,但使用Chrome的Web开发人员工具我可以复制传递给代理的确切查询字符串,将其粘贴到浏览器地址栏中,然后访问该页面而不会有任何问题,这意味着正在构建的网址没有问题。所以我不知道为什么这个返回404。如果有人可以给我任何建议,我将不胜感激。
尽量不要从Chrome浏览器开发工具复制,但要保持断点.NET代码,看看你得到并传递到Web请求的URL,希望这将有助于 –
也尝试过,它构建的网址肯定可以在浏览器中使用,但它仍然是404的,当它碰到GetResponse() – VampiricMonkey