GVKun编程网logo

如何使位置标题使HTTPcaching无效?(设置标题位置)

19

这篇文章主要围绕如何使位置标题使HTTPcaching无效?和设置标题位置展开,旨在为您提供一份详细的参考资料。我们将全面介绍如何使位置标题使HTTPcaching无效?的优缺点,解答设置标题位置的相

这篇文章主要围绕如何使位置标题使HTTPcaching无效?设置标题位置展开,旨在为您提供一份详细的参考资料。我们将全面介绍如何使位置标题使HTTPcaching无效?的优缺点,解答设置标题位置的相关问题,同时也会为您带来$ http的Angular IE Caching问题、.net – 使用basicHttpBinding时使HTTPS工作、apache HttpClient 学习系列--2 之HttpContext、Apache – 如何使http请求变成只有https?的实用方法。

本文目录一览:

如何使位置标题使HTTPcaching无效?(设置标题位置)

如何使位置标题使HTTPcaching无效?(设置标题位置)

在caching失效时 ,HTTP规范说:

一些HTTP方法必须导致caching使实体无效。 这可以是Request-URI引用的实体,也可以是Location或Content-Location头(如果存在)。

我试图通过使用位置标题使我的caching中的条目无效,但似乎没有工作。 这是我的用例:

15:13:23.9988 | GET | folders/folder.34/contents - 200 (OK)

15:13:24.1318 | PUT | folders/folder.34/contents/test.docx - 201 (Created)

15:13:24.1548 | GET | folders/folder.34/contents - 200 (OK) (cached)

(2)的响应包含请求(1)和(3)中使用的URI的Location标头。 我相信这应该使文件夹/文件夹的caching条目无效。但是,根据HttpWebResponse.IsFromCache属性,(3)中的响应看起来好像来自caching。

如果PHP页面未被修改,则返回“304未修改”

Apache:url中的%25(400错误请求)

我可以设置由我的Apache Web服务器提供的PDF文件的“HTML”标题吗?

间歇性慢轨应用程序

网站非常缓慢的Firefox,即时在其他浏览器:KeepAlive问题?

我在“ 位置”标题中尝试了许多URI格式,其中包括:

Location: ../../../folders/folder.34/contents folders/folder.34/ Location: ../../../folders/folder.34/contents (和其他各种“../”计数)

Location: folders/folder.34/contents

Location: /folders/folder.34/contents

Location: http://myhostname/folders/folder.34/contents

但(3)似乎总是来自caching。 我在这里做错了什么?

Nginx,ssl,CORS,以及Access-Control-Allow-Origin值跨站点的caching

如何将httpredirect到https运行Nginx的Elastic Beanstalk?

Nginx的位置正则expression式捕获variables

服务器响应terminal线路分析。 响应热线的最后一部分是什么?

如何使用curl在Windows下发布PUT请求?

HTTPBis更清晰:

http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-22#section-6

Because unsafe request methods (Section 4.2.1 of [Part2]) such as PUT,POST or DELETE have the potential for changing state on the origin server,intervening caches can use them to keep their contents up-to-date. A cache MUST invalidate the effective Request URI (Section 5.5 of [Part1]) as well as the URI(s) in the Location and Content-Location response header fields (if present) when a non-error response to a request with an unsafe method is received.

所以,如果这不是你所看到的行为,我的假设就是你正在使用的特定的HTTP客户端没有正确的行为。

我特别期待:

Location: /folders/folder.34/contents

要有正确的行为。

$ http的Angular IE Caching问题

$ http的Angular IE Caching问题

从IE发送的所有ajax调用均由Angular缓存,我304 response为所有后续调用获取了a
。尽管请求是相同的,但在我的情况下响应不会是相同的。我想禁用此缓存。我尝试将其添加cache attribute到$
http.get中,但仍然无济于事。该问题如何解决?

.net – 使用basicHttpBinding时使HTTPS工作

.net – 使用basicHttpBinding时使HTTPS工作

我正在使用WCF4并且无法通过https获得服务

我已经创建了一个wcf服务并部署到服务器,它在http上工作正常.一旦我将web.config端点地址更改为https,我就会收到错误消息

Service ‘NS.WebWCF.BusinessV1’ has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application,or because no service element matching the service name Could be found in the configuration file,or because no endpoints were defined in the service element.

我的web.config看起来像

<services>
  <service name="NS.WebWCF.Business_v1">
    <endpoint address="https://mydomain.com/business/v1/BusinessV1.svc" binding="basicHttpBinding" bindingConfiguration="" contract="NS.WebWCF.IBusinessV1" listenUri="/" isSystemEndpoint="true">
     </endpoint>
  </service>

我已将IIS设置为需要SSL.但是我得到了上面的错误.

要使https工作,我需要做什么?

解决方法

试试这个:

<system.serviceModel>
  <bindings >

    <webHttpBinding>
      <binding name="webBinding">
        <security mode="Transport">
        </security>
      </binding>
    </webHttpBinding>

  </bindings>

  <services>
    <service ...>
      <endpoint bindingConfiguration="webBinding" .../>
    </service>
  </services>

</system.serviceModel>

apache HttpClient 学习系列--2 之HttpContext

apache HttpClient 学习系列--2 之HttpContext

首先是一个Servlet用于本次试验。

package com.lu.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
public class RirectServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        OutputStream out = response.getOutputStream();
        PrintWriter pw = new PrintWriter(out);

        // 记录返回的内容
        String returnContent = null;

        HttpSession session = request.getSession();
        String user = (String) session.getAttribute("username");

        // 如果不为空,说明已登录
        if (user != null) {
            returnContent = "you have been logined, " + user;
        } else {
            // 为空说明未登录,设置username到session中
            String username = request.getParameter("username");
            session.setAttribute("username", username);
            returnContent = "login success";
        }

        try {
            pw.println(returnContent);
        } finally {
            pw.close();
            out.close();
        }
    }

}

在本机中访问URI为:http://localhost:8080/spiderweb/RirectServlet

下面看请求

package com.lu.test;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

public class HttpClientTest {

    private static HttpContext localContext = new BasicHttpContext();
    private static HttpClientContext context = HttpClientContext
            .adapt(localContext);

    public static void main(String[] args) throws Exception {
        CloseableHttpClient httpClient = HttpClients.createDefault();

        try {
            // 模拟表单
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("username", "**"));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params,
                    "UTF-8");
            HttpPost httpPost = new HttpPost(
                    "http://localhost:8080/spiderweb/RirectServlet");
            httpPost.setEntity(entity);

            // 将HttpClientContext传入execute()中
            CloseableHttpResponse response = httpClient.execute(httpPost,
                    context);

            try {
                HttpEntity responseEntity = response.getEntity();
                System.out.println(EntityUtils.toString(responseEntity));

            } finally {
                response.close();
            }
        } finally {
            httpClient.close();
        }

        CloseableHttpClient httpClient2 = HttpClients.createDefault();

        try {
            HttpGet httpGet = new HttpGet(
                    "http://localhost:8080/spiderweb/RirectServlet");

            // 设置相同的HttpClientContext
            CloseableHttpResponse response = httpClient2.execute(httpGet,
                    context);
            try {
                HttpEntity entity = response.getEntity();
                System.out.println(EntityUtils.toString(entity));
            } finally {
                response.close();
            }
        } finally {
            httpClient2.close();
        }

    }
}

输出结果为:

login success
you have been logined, **


可能大家认为这个结果很正常。第一次登陆了,第二次肯定会输出you have been logined, **。但是大家别忘了,现在不是在浏览器环境下,浏览器会帮你提取服务器传回的sessionId并在你下次请求的时候传给服务器,那么两次请求用的就是同一个session对象,那么自然的就会有上面的输出。

但是现在是在自己写代码访问。我们没有获取sessionId,也没有向服务器传送sessionId,那么两次请求服务器就会为你创建两个sessionId不同的session对象。

那为什么输出结果却是跟浏览器得到的结果一样呢?肯定是什么东西为我们自动完成了获取sessionId传送sessionId的功能。毫无疑问,就是context。 BasicHttpContext里有个Map<Object,Object>的对象用来记录一次请求响应的信息,当响应信息返回时,就会被set到context里,当然响应的cookie信息也就被存储在context里,包括传回的sessionId。

当第二次请求的时候传入相同的context,那么请求的过程中会将context里的sessionId提取出来传给服务器,sessionId一样,自然而然的就是同一个session对象。
那么大家明白context的作用了吗?
按照官方教程的说法来说

代表一个逻辑相关的会话的多个请求序列应该具有相同的HttpContext实例以确保请求之间的信息状态的自动传播



由于初学,不对的地方还望大家指出。

Apache – 如何使http请求变成只有https?

Apache – 如何使http请求变成只有https?

如何判断用户是否使用http://ttt.com或http://www.ttt.com ,将其redirect到https://www.ttt.com ?

httpd.conf中:

<VirtualHost *:80> ServerName www.ttt.com ServerAlias ttt.com DocumentRoot /home/www/html/ttt/public <Directory /home/www/html/ttt/public> #Options ExecCGI #AddDefaultCharset utf-8 DirectoryIndex index.PHP AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

.htaccess:

RewriteEngine On ############################################ ## always send 404 on missing files in these folders #RewriteCond %{REQUEST_URI} !^/(files)/ RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.PHP [NC,L]

使用Apache在PHP上创build一个带有2个参数的友好URL

利用第三方JS的浏览器caching

有条件的DirectoryIndex在.htaccess中

.htaccess更改需要多长时间才能生效?

.htaccess图像URL的RewriteRule

我怎样才能设置CORS访问我的Linux Web服务器上的audio文件与Apache2?

如何在1and1共享主机上configurationCake 2.3.x的htaccess文件

redirect规则与特殊字符

MysqL + htaccess的mod_rewrite?

.htaccess – 重写查询string并redirect到目录

在主目录.htaccess文件中尝试以下代码:

DirectoryIndex index.PHP RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

你可以用httpd.conf来做到这一点:

<VirtualHost *:80> serverName www.ttt.com Redirect "/" "https://www.ttt.com/" </VirtualHost> <VirtualHost *:443> serverName www.ttt.com ... ... </VirtualHost>

或从.htaccess文件中:

RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

这里你去: https : //wiki.apache.org/httpd/RedirectSSL

将请求重定向到SSL

假设您希望http://www.example.com/secure/始终通过SSL发送(我在这里假定普通和SSL虚拟主机都具有相同的内容)&#x3002; 你可以通过链接到你的HTML页面中的正确页面来做到这一点…但总是会有一些用户以这种方式潜入。

使用虚拟主机(使用重定向)

使用SSL时,您至少需要两台虚拟主机:一台用于端口80,用于提供普通请求,另一台用于端口443以提供SSL。 如果您希望将用户从非安全站点重定向到SSL站点,则可以在不安全的VirtualHost内使用普通的Redirect指令:

NameVirtualHost *:80 <VirtualHost *:80> serverName mysite.example.com DocumentRoot /usr/local/apache2/htdocs Redirect permanent /secure https://mysite.example.com/secure </VirtualHost> <VirtualHost _default_:443> serverName mysite.example.com DocumentRoot /usr/local/apache2/htdocs SSLEngine On # etc... </VirtualHost>

当重定向你甚至不需要DocumentRoot的时候:

NameVirtualHost *:80 <VirtualHost *:80> serverName www.example.com Redirect permanent / https://secure.example.com/ </VirtualHost> <VirtualHost _default_:443> serverName secure.example.com DocumentRoot /usr/local/apache2/htdocs SSLEngine On # etc... </VirtualHost>

注意 :重定向也可以在.htaccess文件中使用,或者用于处理特定的URL,如下所示:

例:

重定向永久/登录https://mysite.example.com/login

使用mod_rewrite

虽然建议使用这个解决方案,因为它更简单,更安全,但也可以使用mod_rewrite获得与此处所述相同的效果: RewriteHTTPToHTTPS

从https://httpd.apache.org/docs/trunk/mod/mod_alias.html#redirect :

# Redirect to a URL on a different host Redirect "/service" "http://foo2.example.com/service" # Redirect to a URL on the same host Redirect "/one" "/two"

如果客户端请求http://example.com/service/foo.txt ,则会被告知访问http://foo2.example.com/service/foo.txt 。 这包括使用GET参数的请求,例如http://example.com/service/foo.pl?q=23&a=42 ,它将被重定向到http://foo2.example.com/service/foo.pl&#xFF1F; q = 23&a = 42 。 请注意,POST将被丢弃。 只有完整的路径段被匹配,所以上面的例子不匹配http://example.com/servicefoo.txt的请求&#x3002; 要使用表达式语法进行更复杂的匹配,请按照下面的说明省略URL路径参数。 或者,对于使用正则表达式进行匹配,请参阅RedirectMatch指令。

如果您希望将www.example.com/*和example.com/*重定向,则可以使用不同的serverName创建两个VirtualHost,或者使用Rewrite插件。

总结

以上是小编为你收集整理的Apache – 如何使http请求变成只有https?全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天关于如何使位置标题使HTTPcaching无效?设置标题位置的讲解已经结束,谢谢您的阅读,如果想了解更多关于$ http的Angular IE Caching问题、.net – 使用basicHttpBinding时使HTTPS工作、apache HttpClient 学习系列--2 之HttpContext、Apache – 如何使http请求变成只有https?的相关知识,请在本站搜索。

本文标签: