- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用代理文件来允许我们的系统使用 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/
与来自 HttpWebResponse.GetResponseStream() 的流一起使用的最佳缓冲区大小是多少? 在线示例的大小从 256b 到 5Kb 不等。是什么赋予了?我猜缓冲区大小可能是视
我完全不知道如何解析这个多部分的 httpresponse。这是我收到的格式: MIME-Version: 1.0 RETS-Version: RETS/1.8 RETS-Server: Intere
我试图弄清楚我的网络请求在最终到达最终内容之前被重定向了多少次。 我正在创建我的网络请求,如下所示: var httpRequest = (HttpWebRequest) WebRequest.Cre
我是 c# 的新手,正在制作一个简单的代理来编辑某些 header 。 我已经使用 HttpLisenter 获取请求,然后使用 HttpWebRequest 和 Response 进行编辑、发送和接
这个问题在这里已经有了答案: Garbled httpWebResponse string when posting data to web form programmatically (1 个回答
我有一些代码可以下载我已经使用了一段时间的网页的内容。这段代码工作正常,从来没有出现过问题,现在仍然没有……但是,有一个页面相当大(2MB,没有图像),有 4 个表,分别有 4、20、100、600
我正在开发一个每 5 秒自动查询一次网站的程序。它在过去几天一直运行良好,但今天当我只是重新启动它时,它一直在下面标记的行上抛出 System.ObjectDisposedException。我应该提
我收到来自 HttpWebRequest 的回复(使用修改后的版本 Jeff Richter's CCR wrappers ),然后检查一些 header 以决定是否继续下载。有时我可能不想继续,所以
我遇到了编码问题。当我获得网站的源代码时,我有: 我像这样将编码设置为 UTF8: StreamReader reader = new StreamReader(response.GetRespons
我在下面的代码中收到超时异常。只有这个网站有问题。有什么问题? string ackoURL = "https://www.zomato.com/sk/brno/u-heligonky-z%C3%A1
我正在尝试编写一个重定向检查器,我的解决方案是今天早上刚刚组合在一起的,所以它不是最有效的,但除了一件事之外它可以完成我需要它做的所有事情: 它只在停止前检查两个站点,没有发生错误,它只是在“requ
我正在使用以下代码来读取响应: using (Stream MyResponseStream = hwresponse.GetResponseStream()) { byte[] My
我有一个帮助程序类,它有一个方法,该方法设置为获取信息以生成 HttpWebRequest。目前的方法返回一个 HttpWebResponse。 HttpWebResponse httpRespons
我正在编写自定义 ActionFilterAttribute 并尝试将一些数据直接写入 ASP.NET MVC 3 中的输出流。我正在编写的数据就是我需要响应的所有数据,但是在我的数据渲染 View
使用 Fiddler 运行以下代码显示加号正在转换为某种空白字符。我应该使用什么编码来防止数据被转换?我想保留加号等。 编辑:更新的代码示例 string postData = "test1=test
我们公司与另一家名为 iMatrix 的公司合作,他们拥有用于创建我们自己的表单的 API。他们已经确认我们的请求正在访问他们的服务器,但响应应该以由参数确定的几种方式之一返回。我收到 200 OK
应用正在与 REST 服务对话。Fiddler 显示完整的良好 XML 响应作为 Apps 响应该应用程序位于法属波利尼西亚,在新西兰有一个相同的副本,所以主要嫌疑人似乎在编码,但我们已经检查过了,结
HttpWebResponse.LastModified 是否准确?它总是存在吗?我的项目是创建一种专注的网络爬虫,如果我将使用资源的哈希值或仅使用 HttpWebResponse.LastModif
我有一个用 C# 编写的 ASP.NET 3.5 服务器应用程序。它使用 HttpWebRequest 和 HttpWebResponse 向 REST API 发出出站请求。 我已经设置了一个测试应
我有制作HTTP POST的方法 我这样用try catch调用这个方法 try { returnString = MakePost(gatewayEnpoint, data); retu
我是一名优秀的程序员,十分优秀!