gpt4 book ai didi

c# - 远程服务器返回错误 : (404) Not Found - HttpWebResponse

转载 作者:行者123 更新时间:2023-11-29 17:21:20 24 4
gpt4 key购买 nike

我正在使用代理文件来允许我们的系统使用 ajax 从我们系统的不同子域加载页面。我第一次尝试成功地做到了这一点,但我的第二次尝试给了我一个错误,我正在努力找出原因,我们将不胜感激。

首先这是我的 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() 函数来构建我需要从子域上的项目获取的任何页面的 url。

我使用一个 url 完全没有问题,但是第二次尝试时我收到了这个错误:

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)

对我来说,这表明我正在构建的 url 有问题,但是使用 Chrome 的网络开发人员工具,我可以复制出传递给代理的确切查询字符串,将其粘贴到浏览器地址栏中,然后访问该页面而无需任何根本没有问题,这意味着正在构建的 url 没有问题。所以我不知道为什么这个返回 404。如果有人能给我任何建议,我将不胜感激。

最佳答案

尝试在 AJAX 代码中使用“GET”而不是“POST”

关于c# - 远程服务器返回错误 : (404) Not Found - HttpWebResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12638013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com