我知道我们可以轻松地在任何http 请求标头上建立RewriteCond .但是我们可以检查(某些)将要发送的响应标头吗?特别是最后修改过的一个?
我想只在最后修改日期超过30分钟时重写一个URL,并且我试图避免每次请求该目录中的文件时将该检查委托给php文件的开销.
提前致谢!
如何重定向到DJANGO中包含非ascii字符的查询字符串URL?
当我使用包含字符的return HttpResponseRedirect(u'/page/?title=' + query_string)地方时,我收到错误query_string??
'ascii'编解码器不能编码21-26位的字符:序号不在范围内(128),HTTP响应头必须是US-ASCII格式...
我有一个客户端和一个服务器.
在客户端我有:
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://localhost/fa/Default.aspx");
request.Method = "POST";
byte[] data = Encoding.ASCII.GetBytes(GetSAMLRequestB64());
request.ContentType = "text/xml";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Run Code Online (Sandbox Code Playgroud)
在服务器端,我有:
public void ProcessRequest(HttpContext httpContext)
{
HttpResponse response = httpContext.Response;
response.Clear();
response.BufferOutput = true;
response.StatusCode = 200; // HttpStatusCode.OK;
response.Write("Hello");
response.ContentType = "text/xml";
response.End();
}
Run Code Online (Sandbox Code Playgroud)
客户端收到正确的响应StatusCode.虽然,如果我(int)response.ContentLength;在客户端上,我得到0.我收到响应(客户端)后,我无法读取字符串"Hello".
当读取HttpResponse时,下面的方法会出现错误:"已消耗内容".我知道内容只能被消耗一次,但是我在第一次尝试时遇到了这个错误,我在代码中没有看到我可能会消耗它两次.
private static String getData(String url, HttpParams params) {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
if (params != null) {
httpGet.setParams(params);
}
String result = "";
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
content.close(); …Run Code Online (Sandbox Code Playgroud) 只想运行我在服务器端与Jersey的分页方法,以及客户端上的JQuery.
在服务器上(假设用户刚刚请求/休息/用户?page = 1):
// Hardcoded the page number here, but it would be page-1, page+1
String prevLink = uriInfo.getRequestUri() + "?page=0";
String nextLink = uriInfo.getRequestUri() + "?page=2";
String linkHeader = String.format(LINK_HEADER_TMPL, prevLink, nextLink);
return List<User> currentPageResults;
Run Code Online (Sandbox Code Playgroud)
这给了我响应中的以下标题:
Link: <http://localhost:8880/rest/users?page=0>; rel="prev", <http://localhost:8880/rest/users?page=2>; rel="next"
Run Code Online (Sandbox Code Playgroud)
在客户端:
var xhr = $.getJSON("rest/users", function(allData) {
var links = (xhr.getResponseHeader("link")).split(',');
var relLinks = [];
$.each(links, function(index, value) {
var parts = value.split(';');
var url = parts[0].replace(/^.*<(.*)>.*$/m, '$1');
var rel = parts[1].replace(/^.*"(.*)".*$/m, '$1');
relLinks[rel] = url;
}); …Run Code Online (Sandbox Code Playgroud) 我试图从HTTP响应中获取JSONObject.
try
{
GetMethod postMethod = new GetMethod();
postMethod.setURI(new URI(url, true));
postMethod.setRequestHeader("Accept", "application/json");
httpClient.executeMethod(postMethod);
String resp=postMethod.getResponseBodyAsString();
org.json.JSONTokener tokener = new org.json.JSONTokener(resp);
finalResult = new org.json.JSONArray(tokener);
return finalResult;
}
Run Code Online (Sandbox Code Playgroud)
但我收到了运行时警告
去缓冲大或未知大小的响应体.使用
getResponseBodyAsStream建议来代替.
我应该按照JVM的建议获得响应吗?如果是这样,我怎么能解析它的JSON?
在NGINX提供的任何响应中,如何删除"Connection:keep-alive"标题?
我们为来自NGINX的10个客户提供100B + /月的子100字节响应,用于基于RTB的广告服务.我们正在尝试最小化开销(数据大小)以节省带宽成本.我们不希望实际让NGINX关闭连接,只将其从标头中删除.客户端不是浏览器,将根据HTTP/1.1规范保持连接打开.
我们已经使用HttpHeadersMoreModule从"无操作"响应(204)中成功删除了默认响应头.它看起来像这样:
HTTP/1.1 204 No Content
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
我们想要删除其他标头,因此它看起来像这样:
HTTP/1.1 204 No Content
Run Code Online (Sandbox Code Playgroud)
我们的keepalive_timeout设置为没有第二个值.根据NGINX HttpCoreModule文档,如果没有此[second]参数,nginx不会发送Keep-Alive标头.外出设置是:
keepalive_timeout 60s;
Run Code Online (Sandbox Code Playgroud)
我们尝试过使用和设置http://wiki.nginx.org/HttpHeadersMoreModule#more_clear_headers 和http://wiki.nginx.org/HttpHeadersMoreModule#more_clear_input_headers:
more_clear_headers 'Connection';
more_clear_input_headers 'Connection';
Run Code Online (Sandbox Code Playgroud)
我们也尝试过:
rewrite_by_lua '
ngx.req.clear_header("Connection")
';
Run Code Online (Sandbox Code Playgroud)
甚至是:
more_clear_headers 'Connection*';
Run Code Online (Sandbox Code Playgroud)
但我们仍然看到标题.我们发送的回复如此之多,以至于Connection标题实际上花费了我们每月200美元的费用.
任何帮助表示赞赏.
相关和有用:Nginx和原始标头
我正在使用http.request函数发送一个http请求,我想读取整个http响应,如文本; 也就是原始的http协议文本.可能吗?我写了下面的代码,但它没有用.
// Set up the request
console.log('Sending request');
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
console.log('Response statusCode: ' + res.statusCode);
// res.on('data', function (chunk) {
// console.log('Response: ' + chunk);
// });
// res.on('end', function() {});
});
post_req.on('socket', function (socket) {
var response = "";
socket.on('data', function(chunk){
console.log(chunk);
});
});
// post the data
post_req.write(post_data);
post_req.end();
Run Code Online (Sandbox Code Playgroud) 我创建了一个Controller和方法,用于从API获取数据.我HttpResponseMessage用来得到回应.一切正常,但我无法获得我想要的JSON格式的确切数据.
方法如下所示:
public class TestController : ApiController
{
[HttpGet]
public async Task<IHttpActionResult> TestMethod(...)
{
string _apiUrl = String.Format("...");
string _baseAddress = "...";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_baseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync(_apiUrl);
if (response.IsSuccessStatusCode)
{
return Json(response);
}
}
return NotFound();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的回应如下:
{
"Version": {
"Major": 1,
"Minor": 1,
"Build": -1,
"Revision": -1,
"MajorRevision": -1,
"MinorRevision": -1
},
"Content": {
"Headers": [
{
"Key": "Content-Length",
"Value": [ …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个单页面应用程序(SPA),它使用一个与SPA域中托管的域不同的域作为端点(即:site.com和site-api.comor api.site.com).
访问控制标头已在后端设置,Max-Age包括在内,但它似乎不起作用.
以下是我多次执行相同调用时会发生什么的示例:
这些是服务器标头:
AUTHORIZATION,CONTENT-TYPEPATCHhttp://tovertaal.test:3000600第一次请求600秒内不应该Max-Age600防止其他所有请求吗?OPTIONSOPTIONS
服务器端点是http://tovertaal-api.test.
httpresponse ×10
c# ×2
http ×2
http-headers ×2
json ×2
.htaccess ×1
.net ×1
android ×1
asp.net-mvc ×1
django ×1
java ×1
java-ee ×1
javascript ×1
jersey ×1
jquery ×1
keep-alive ×1
mod-rewrite ×1
nginx ×1
node.js ×1
pagination ×1
python ×1
sockets ×1
unicode ×1
xml ×1