当http请求进入我的服务器时,如何检测它是来自iphone,android还是其他设备?
我有一个配置了Windows身份验证和URL重写的IIS实例,因此它基本上用作反向代理.我的后端服务器(在Linux上运行)需要一个REMOTE_USER标头.是否可以配置IIS以将有关经过身份验证的用户的信息传递给后端服务器?
authentication iis reverse-proxy basic-authentication http-headers
我正在使用jQuery的ajax调用来发出CORS请求,如果我设置它的工作
var headers = {};
Run Code Online (Sandbox Code Playgroud)
但是,由于我想要获得的内容相当大,我想发送范围标题.
(这都经过测试并在同一个域中工作)
所以,当我这样做时:
var headers = {"Range":"bytes=" + start + "-" + end};
$.ajax({
url:url,
type:type,
headers:headers,
dataType:dataType,
success:function (data, status, jqXHR) {
//
}, error:function (data, status, jqXHR) {
//
}
});
Run Code Online (Sandbox Code Playgroud)
对于我们的其他域,请求在最新的chrome和FF中被取消.
如果我关闭标题,一切正常,但随后我得到兆字节的数据,浏览器无法处理/解析该数据量.
这是来自服务器的标题(我控制它,所以我可以编辑它)
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS, GET, POST
Access-Control-Allow-Headers: Content-Type, Authorization, Accept, Range, Origin
Access-Control-Expose-Headers: Content-Range
Access-Control-Max-Age: 3600
Run Code Online (Sandbox Code Playgroud)
我做错了什么,或者通过CORS发送范围请求还没有在最新的浏览器中正确实现?
(旁注,即使我在Expose-Headers中允许它们,Chrome也不会返回标题,但这是铬邮件列表中的已知错误,但我可以首先获取一个请求以查找文件大小)
为了提高我网站的性能/响应能力,我使用AJAX,replaceState,pushState和popstate监听器实现了部分页面加载.
我基本上将页面的中心部分(HTML)存储为历史记录中的状态对象.单击链接时,我只从服务器请求页面的中心位(用不同的Accept标识标识这些请求)并用javascript替换它.在popstate上,我抓住前面的中央部分并将其推回到dom中.
这大部分工作正常,但我发现了一个我坚持的特殊问题.解释起来有点复杂,所以如果不是很清楚我会道歉.
我们的大部分页面都有一个搜索表单.通过ajax加载部分页面仅在GET请求上,并且表单执行POST,导致整页加载.
如果我浏览下面的一组页面,我最终会出现一个格式错误的部分页面,其中只包含中心内容,而不包含任何周围的dom:
从主页开始(通过整页加载) - 执行搜索(重定向后)
获取搜索结果(通过整页加载) - 然后单击主页
返回主页(通过动态获取) - 单击浏览器返回
搜索结果(来自popstate listener) - 单击浏览器返回
格式错误的主页.
当出现格式错误的主页时,我的popstate监听器根本不存在.
我认为正在发生的是,主页的第二次加载(动态,部分)被浏览器缓存,然后当整页回复发生时,浏览器只显示缓存的部分响应而不是整页.
为了解决这个问题,我在响应中添加了一个Vary:Accept标头,让浏览器知道内容可能会根据accept标头发生变化.我还为部分加载的内容添加了Cache-Control max-age = 0,pragma no-cache和过去的到期日期,以试图强制浏览器不缓存它,但这些都没有解决它.
不幸的是我的公司不允许我们的开发服务器的外部流量,所以我不能告诉你这个问题.我在这里看过各种类似的问题,但它们似乎都不一样,所提出的解决方案似乎也没有用.
如果我向动态GET请求添加一个无意义的参数(blah = blah),这就解决了这个问题.然而,这是一个丑陋的黑客,我宁愿不做.这似乎应该可以解决标题,因为我认为这是一个缓存问题.谁能解释一下发生了什么?
我需要将数据发布到服务器(带有"referer"头字段)并在Webview中加载响应.
现在,有不同的方法(来自Android WebView)来做它的一部分,比如:
void loadUrl(String url, Map<String, String> additionalHttpHeaders)
Run Code Online (Sandbox Code Playgroud)
使用指定的其他HTTP标头加载给定的URL.
void loadData(String data, String mimeType, String encoding)
Run Code Online (Sandbox Code Playgroud)
使用"数据"方案URL将给定数据加载到此WebView中.
void postUrl(String url, byte[] postData)
Run Code Online (Sandbox Code Playgroud)
使用"POST"方法将带有postData的URL加载到此WebView中.
loadUrl()允许发送HttpHeaders但不允许发送post数据,其他方法似乎不允许发送HttpHeaders.我错过了什么或我正在尝试的是不可能的?
根据Firebug,这是第一次检索资源时的响应头:
Accept-Ranges bytes
Cache-Control public, max-age=86400
Content-Language en
Content-Length 232
Content-Location http://localhost/myapp/cacheTest.html
Content-Type text/html; charset=WINDOWS-1252
Date Wed, 05 Sep 2012 15:59:31 GMT
Last-Modified Tue, 01 May 2012 05:00:00 GMT
Server Restlet-Framework/2.0.3
Vary Accept-Charset, Accept-Encoding, Accept-Language, Accept
Run Code Online (Sandbox Code Playgroud)
我点击了然后点击返回,这里是发送到服务器的请求标头:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Host localhost
Referer http://localhost/myapp/cacheTest2.html
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0
Run Code Online (Sandbox Code Playgroud)
所以,当然,服务器不能像我想的那样发送304,而是再次发送整个资源.
这在Firefox 14中发生,我认为它可能是一个错误,所以我升级了.但它仍然在Firefox 15中发生.Chrome没有问题.
无论有没有"Expires"标题我都尝试过,它没有任何区别.Firefox只是拒绝发送If-Modified-Since标头.
我刚刚发现我的浏览器在尝试使用自定义http标头进行跨域ajax调用时发送了一个额外的"OPTION"请求.我认为它被称为"预检请求".
是否可以禁用此功能并发送初始请求?
这是我的javascript测试代码:
$(document).ready(function() {
$.ajax({
url: "http://google.fr",
crossDomain: true,
headers: {
"X-custom-parameter": true
}
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我的帖子方法是这样的:
public HttpResponseMessage AddUser(User user)
{
UserManager userManager = new UserManager();
try
{
userManager.Create(user);
var savedUser = userManager.FindUserByClientId(user.ClientId);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = savedUser.Id }));
return response;
}
catch(Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
在角度,我试图读取位置标题,但到目前为止,我仍然无法.
return $http.post('http://localhost:30028/api/values/adduser', user)
.success(function (data, status, headers, config) {
alert(angular.toJson(data));
alert(angular.toJson(status));
alert(angular.toJson(headers));
alert(angular.toJson(config));
};
Run Code Online (Sandbox Code Playgroud)
我只是检查每个的内容,没有没有位置标题.是否有角度访问位置标题,以便我知道我的新对象的网址?
public static class HttpRequestHelper
{
public static string RequestBody()
{
var bodyStream = new StreamReader(HttpContext.Current.Request.InputStream);
bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
var bodyText = bodyStream.ReadToEnd();
return bodyText;
}
}
Run Code Online (Sandbox Code Playgroud)
我打算从ActionFilters中调用它来记录传入的请求.当然可能有多个同时发出的请求.
这种方法可以吗?
我正在用Selenium编写一些测试,并注意到,Referer标头中缺少该测试。我编写了以下最小示例,以使用https://httpbin.org/headers进行测试:
import selenium.webdriver
options = selenium.webdriver.FirefoxOptions()
options.add_argument('--headless')
profile = selenium.webdriver.FirefoxProfile()
profile.set_preference('devtools.jsonview.enabled', False)
driver = selenium.webdriver.Firefox(firefox_options=options, firefox_profile=profile)
wait = selenium.webdriver.support.ui.WebDriverWait(driver, 10)
driver.get('http://www.python.org')
assert 'Python' in driver.title
url = 'https://httpbin.org/headers'
driver.execute_script('window.location.href = "{}";'.format(url))
wait.until(lambda driver: driver.current_url == url)
print(driver.page_source)
driver.close()
Run Code Online (Sandbox Code Playgroud)
哪些打印:
<html><head><link rel="alternate stylesheet" type="text/css" href="resource://content-accessible/plaintext.css" title="Wrap Long Lines"></head><body><pre>{
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.5",
"Connection": "close",
"Host": "httpbin.org",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
}
}
</pre></body></html>
Run Code Online (Sandbox Code Playgroud)
所以没有 …
http-headers ×10
ajax ×2
cross-domain ×2
post ×2
android ×1
angularjs ×1
asp.net-mvc ×1
c# ×1
cors ×1
firefox ×1
html5 ×1
http ×1
http-referer ×1
httpcontext ×1
iis ×1
jquery ×1
mobile ×1
option ×1
popstate ×1
preflight ×1
pushstate ×1
python ×1
request ×1
selenium ×1
testing ×1
webserver ×1
webview ×1