Tag: http headers

Spring-WS:指定Content-Type

我有一个基于AbstractJDomPayloadEndpoint的Spring Web服务。 此服务工作正常,但我的客户端需要将HTTP标头Content-Type设置为正确的字符集(在我的情况下为utf-8)。 我无法找到我可以配置的地方。 我尝试编写一个简单的servlet Filter : chain.doFilter(request, response); HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader(“Content-Type”, “text/xml; charset=utf-8”); 但这根本不会改变标题。 我怀疑内容类型标头是由Spring-WS设置的,并且响应是提交的,因此我在filter中设置的任何内容都不会产生影响。 我的appserver是WebLogic 9.2.3。

使用Apache HttpClient的Java HTTPPost请求

我需要一个java程序来生成以下请求。 我正在使用Apache HttpClient库,但仍然无法生成这样的请求: 这是我的python程序生成的,我写了一个等效的java程序。 但它的投掷403。 2012-09-10 15:12:05G INFO:G2OAuth auth data =“3,0.0.0.0,0.0.0.0,1347289925,3223833979,crlakamai”2012-09-10 15:12:05G INFO:G2OAuth sign string =“ 3,0.0.0.0,0.0.0.0,1347289925,3223833979,akamai / 182228 \ nx-akamai-acs-action:version = 1&action = dir&format = xml \ n“ send: ‘POST /182228 HTTP/1.1\r\nHost: crl.api.akamailab.com\r\nAccept-Encoding: identity\r\nX-Akamai-ACS-Auth-Data: 3, 0.0.0.0, 0.0.0.0, 1347289925, 3223833979, crlsymc\r\nX-Akamai-ACS-Auth-Sign: eFnWtJBIyj4rxV3V0axF3w==\r\nX-Akamai-ACS-Action: version=1&action=dir&format=xml\r\n\r\n’ reply: ‘HTTP/1.1 200 OK\r\n’ header: Server: Apache header: Content-Type: text/html header: Date: […]

如何确定给定的URL链接是video还是图像?

我正在尝试获取用户输入的给定URL,并确定该URL是指向图像还是video。 用例示例: 当用户粘贴YouTubevideo的url时,在保存页面时会自动显示嵌入的YouTube播放器。 当用户在Flickr中发布图片的URL时,在保存时,该页面将自动显示较小版本的Flickr图像。

如何(简单地)从java生成POST http请求来进行文件上传

我想使用POST http事件从java application / applet上传文件。 我想避免使用SE中未包含的任何库,除非没有其他(可行的)选项。 到目前为止,我只提出了非常简单的解决方案。 – 创建字符串(缓冲区)并用兼容的标题填充它( http://www.ietf.org/rfc/rfc1867.txt ) – 打开与服务器URL.openConnection()的连接,并将此文件的内容写入OutputStream。 我还需要手动将二进制文件转换为POST事件。 我希望有更好,更简单的方法来做到这一点?

Amazon SES自定义标头List-Unsubscribe无效

我正在尝试在我发送的电子邮件中添加“List-Unsubscribe”标题(通过amazon ses)但是当我看到收到的电子邮件时,其中没有这样的标题。 我需要它来减少垃圾邮件投诉的数量,并提高可传递性和声誉。 SendEmailRequest sendEmailRequest = new SendEmailRequest(); sendEmailRequest.putCustomRequestHeader(UNSUBSCRIBE_HEADER, unsuscribeURL); PS:使用其他提供商,如Mandrill或Sendgrid,它可以工作,但我真的需要它在亚马逊

URLConnection setRequestProperty vs addRequestProperty

让我说我正在谈论HTTP到Web服务器,我会接受HTML或文本,但更喜欢HTML。 换句话说,标题应该说(我想!) 接受:text / html,text / * 我正在使用Java,所以我有一个URLConnection。 我应该使用: myUrlConnction.setRequestProperty(“Accept”, “text/html”); myUrlConnction.addRequestProperty(“Accept”, “text/*”); 要么 myUrlConnction.setRequestProperty(“Accept”, “text/html, text/*”); 或者他们是等同的??? 一般来说,我看到的大多数第三方代码似乎并不担心这些标题的排序或多个值,所以我想知道它是如何最终起作用的。

Spring Global CORS配置不起作用,但控制器级配置不起作用

我试图通过WebMvcConfigurerAdapter显示的WebMvcConfigurerAdapter全局配置CORS。 测试我通过我创建的小节点应用程序来模拟外部服务。 当我尝试这种方法时,响应不包含正确的标题并且失败 XMLHttpRequest cannot load http://localhost:8080/api/query/1121. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:333’ is therefore not allowed access. 全球配置 import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @EnableWebMvc @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping(“/api/query/**”) .allowedOrigins(“*”) .allowedHeaders(“*”) .allowCredentials(true); } } 但是,当我使用@CrossOrigin注释时,它可以很好地响应正确的标题。 @CrossOrigin(origins = […]

如何在Spring-ws端点访问HTTP头?

如何在Spring-ws端点中访问HTTP头? 我的代码如下所示: public class MyEndpoint extends AbstractMarshallingPayloadEndpoint { protected Object invokeInternal(Object arg) throws Exception { MyReq request = (MyReq) arg; // need to access some HTTP headers here return createMyResp(); } } invokeInternal()仅获取未编组的JAXB对象作为参数。 如何在invokeInternal()访问请求附带的HTTP头? 一种可能有效的方法是创建一个Servletfilter,将头值存储到ThreadLocal变量,然后在invokeInternal()访问,但是有更好的,更类似Spring的方法吗?

如何用Java解析HTTP请求?

实现代理服务器时,我得到一个HTTP请求作为字符串,例如: GET http:// localhost:54321 / x HTTP / 1.1 主持人:localhost:54321 缓存控制:无缓存 是否有内置类来解析此请求?

未在servlet中的请求中插入自定义标头

有一个需要通过自定义http标头获取信息的四方派对应用程序,因此我编写了一个简单的测试应用程序,创建此标题,然后重定向到列出所有标题的页面。 生成标头的servlet片段是: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(“text/plain”); response.setHeader(“cust-header”, “cust-val”); response.sendRedirect(“header.jsp”); } 另一方面,header.jsp的相关代码是: <% Enumeration enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String string = (String)enumeration.nextElement(); out.println("” +string +”: ” + request.getHeader(string)+ “”); } %> 这显示以下标题: Host: localhost:9082 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; es-ES; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 (.NET CLR […]