Tag: http

res.flushBuffer()vs res.getOutputStream()。flush();

打电话有什么区别: res.flushBuffer(); 与 res.getOutputStream().flush(); 这些方法是否刷新相同的缓冲区? 如果是这样,你能给我一个关于servlet容器如何管理这个缓冲区的线索吗?

如何使用JAX-RS转发请求?

我想将REST请求转发给另一台服务器。 我使用JAX-RS与Jersey和Tomcat。 我尝试设置See Other响应并添加Location标头,但它不是真正的前进。 如果我使用: request.getRequestDispatcher(url).forward(request, response); 我明白了: java.lang.StackOverflowError :如果url是相对路径 java.lang.IllegalArgumentException :路径http://website.com不以/字符开头(我认为转发仅在同一个servlet上下文中合法)。 我该如何转发请求?

wit.ai – 如何用Java发送请求?

我正在使用Java中的wit.ai开发一个虚拟助手,但是我仍然无法发出HTTP请求。 我不是Java中的HTTP请求的专家,我一直得到400错误。 这是我的代码: public class CommandHandler { public static String getCommand(String command) throws Exception { String url = “https://api.wit.ai/message”; String key = “TOKEN HERE”; String param1 = “20141022”; String param2 = command; String charset = “UTF-8”; String query = String.format(“v=%s&q=%s”, URLEncoder.encode(param1, charset), URLEncoder.encode(param2, charset)); URLConnection connection = new URL(url + “?” + query).openConnection(); connection.setRequestProperty (“Authorization […]

将Cookie传递给GET请求的问题(POST后)

我现在被困在这个问题好几天了,我的眼睛开始受伤于尝试不同组合的时间,但没有成功。 问题是,我正在制作一个应用程序,它必须从互联网上获取数据,解析它然后显示给用户。 我已经尝试了几种方法,并且使用JSOUP非常有帮助,特别是在解析和从结果中获取数据时。 但是,有一个问题我无法解决。 我已尝试使用常规HTTPClient和JSOUP,但我无法成功获取所需的数据。 这是我的代码(JSOUP版本): public void bht_ht(Context c, int pozivni, int broj) throws IOException { //this is the first connection, to get the cookies (I have tried the version without this method separate, but it’s the same Connection.Response resCookie = Jsoup.connect(“http://www.bhtelecom.ba/imenik_telefon.html”) .method(Method.GET) .execute(); String sessionId = resCookie.cookie(“PHPSESSID”); String fetypo = resCookie.cookie(“fe_typo_user”); //these two […]

完成HttpServletResponse但继续处理

我的情况似乎符合Async Servlet 3.0 / Comet情况,但我需要做的就是在接受传入参数后返回200响应代码(或其他)。 有没有办法让HttpServlet完成http请求/响应握手并继续处理? 就像是… doPost( req, response ) { // verify input params… response.setStatus( SC_OK ); response.close(); // execute long query } 编辑:看看javax.servlet包 – 我的问题的正确措辞是 我如何提交回复? 在Servlet.isCommitted()中

HttpURLConnection conn.getRequestProperty返回null

我正在尝试将一些数据推送到BES的URL(MDS_CS) 当我在我的代码中设置一些请求标头并提交请求时,提交的请求的标头被设置为null 。 这是我的代码: HttpURLConnection conn =(HttpURLConnection)url.openConnection(); conn.setDoInput(true);//For receiving the confirmation conn.setDoOutput(true);//For sending the data conn.setRequestMethod(“POST”);//Post the data to the proxy conn.setRequestProperty(“X-Rim-Push-ID”, pushId); conn.setRequestProperty(“Content-Type”, “text/html”); conn.setRequestProperty(“X-Rim-Push-Title”, “-message”); conn.setRequestProperty(“X-Rim-Push-Type”, “browser-message”); conn.setRequestProperty(“X-Rim-Push-Dest-Port”, “7874”); //Write the data OutputStream out = conn.getOutputStream(); out.write(data.getBytes()); out.close(); System.out.println(conn.getHeaderField(“X-Rim-Push-ID”)); 当我尝试检索X-Rim-Push-Title时,最后一行返回null只有正确检索的X-Rim-Push-ID为NULL 请帮我

在App Engine上的Servlet响应中覆盖与缓存相关的HTTP标头

我在App引擎上有一个servlet来提供图像。 servlet正确设置HTTP标头值以指示应缓存图像。 但App Engine会覆盖这些标题,导致图像未被缓存。 请注意,之前使用相同的代码,但现在它不起作用。 App引擎文档指出,如果servlet设置了Cache-Control , Expires和Vary标头,它们将保持不变: https : //developers.google.com/appengine/docs/java/runtime#Responses 这是我的示例代码: response.setContentType( “image/jpeg” ); //response.setDateHeader( “Expires”, new Date().getTime() + 60L*24*60*60*1000 ); // 60 days cache time //response.addHeader( “Cache-Control”, “public, max-age=5184000” ); // 5_184_000 sec = 60 days cache time response.addHeader( “Cache-Control”, “public, max-age=90000” ); // 90_000 sec = 25 hours cache time response.getOutputStream().write( data […]

在java中模拟https请求

假设我正在编写一个应用程序,我需要能够执行以下操作: String url = “https://someurl/”; GetMethod method = new GetMethod(URLEncoder.encode(url)); String content = method.getResponseBodyAsString(); 有没有办法提供一个模拟服务器让我处理https请求? 我正在寻找的是一种编写unit testing的方法,但是我需要能够模拟实际发布到https:// someurl的部分,这样我才能得到已知的响应。

Java获取referer URI?

我想要与getRequestURI()完全相同的方法,但我想在referer上使用它。 这可能吗? 我想将http://www.example.com/my/path?vars=true转入/my/path

压缩Http接头

它发生的事实是我的实际数据是HTTP请求头大小的1/4(以字节为单位)。 有没有办法减少HTTP标头的大小或任何其他相关的方式来处理这种情况? 我正在通过GPRS将数据从移动设备发送到服务器,并且不想承担大量的请求数据包,这会占用我的$$和带宽。