Tag: http

如何使用JAX-RS NewCookie删除服务器上的cookie?

我想删除服务器上的cookie(通过将Expires设置为过去)。 我怎么能用javax.ws.rs.core.NewCookie做到这一点? 我正在尝试这个,但它不起作用: return Response.ok() .entity(“hello world!”) .cookie( new NewCookie( “foo”, “”, “/”, “.example.com”, 1, “no comment”, 0, // maxAge false ) ) .build(); 此代码段生成此HTTP标头: Set-Cookie:foo=;Version=1;Comment=”no comment”;Domain=.example.com;Path=/ 此标头不会从服务器中删除cookie。 什么是可能的解决方法?

GRIZZLY0023 Glassfish警告

我在GlassFish服务器上的java中部署了2个Web应用程序。 我正在使用Glassfish Server 3.1.2.2。 它们都有来自接收http请求的java servlet页面,代码也是相同的,只有不同的参数(针对不同的客户端)。 第一个工作正常,另一个处理http请求很长。 之后我注意到了下一件事: 我经常在Netbeans的Glassfish输出中收到此警告。 WARNING: GRIZZLY0023: Interrupting idle Thread: http-thread-pool-9990 任何人都可以解释我为什么会得到这个警告,以及如何解决它。

通过Javascript缓存与在Server中设置HTTPResponse头之间有什么区别?

在前端,我使用AngularJS“$ resource”作为GET请求,在后端我使用SpringMVC公开我的方法Restful方式。 现在我想只缓存一些我的GET请求。 我注意到有一些方法可以像使用$ cacheFactory一样。 或类似的东西: return { Things: $resource(‘url/to/:thing’, {}, { list : { method : ‘GET’, cache : true } }; 请注意,这也可能是一个带有一些缓存参数的简单ajax调用,而不是必须使用angularJS。 所以不是在客户端上使用这种方法,我不知道它可以在服务器上完成,只需通过Java在Response头中设置缓存,有些事情如下: response.setHeader(“Cache-Control: max-age=2592000”); 这两种方法有什么区别? 应该采用哪种方法? PS这个问题不是服务器端缓存与客户端缓存问题,我只需在服务器中设置HTTPResponse头即可。

调用Restful Webservice时,Uri不是绝对exception

以下代码段用于使用restful API调用我的Web服务。 ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); String uri= “https://127.0.0.1:8443/cas-server-webapp-3.5.0/login”; WebResource resource = client.resource(URLEncoder.encode(uri)); MultivaluedMap queryParams = new MultivaluedMapImpl(); queryParams.add(“username”, “suresh”); queryParams.add(“password”, “suresh”); resource.queryParams(queryParams); ClientResponse response = resource.type( “application/x-www-form-urlencoded”).get(ClientResponse.class); String en = response.getEntity(String.class); System.out.println(en); 并在运行上述代码时获得此exception com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151) at com.sun.jersey.api.client.Client.handle(Client.java:648) at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680) 我搜索了许多文章,并没有得到我做错的地方。 旁注:我在Apache tomacat7的机器上部署了cas-server-webapp-3.5.0 war

每个请求是否都访问相同的servlet对象?

每个HTTP请求是否访问相同的servlet对象但是在不同的线程中? 或者它是否创建了一个新线程和新的Servlet实例?

Java – HttpUrlConnection每次都返回缓存的响应

我正在尝试收集Roblox货币兑换的统计数据进行分析。 因此,我需要最新的数据而不是缓存的结果。 但是,似乎无论我做什么,结果仍然是缓存的。 似乎最直观的选项setUseCaches()没有效果,并且手动将头设置为Cache-Control: no-cache似乎也不起作用。 我使用Fiddler2检查了Cache头,看到它的值是Cache-Control: max-age=0 ,但它似乎也没有改变程序的行为。 以下是相关的代码: url: private final static String URL = “http://www.roblox.com/my/money.aspx#/#TradeCurrency_tab”; GET请求: URLConnection socket = new URL( URL ).openConnection( ); socket.setUseCaches( false ); socket.setDefaultUseCaches( false ); HttpURLConnection conn = ( HttpURLConnection )socket; conn.setUseCaches( false ); conn.setDefaultUseCaches( false ); conn.setRequestProperty( “Pragma”, “no-cache” ); conn.setRequestProperty( “Expires”, “0” ); conn.setRequestProperty( “Cookie”, “.ROBLOSECURITY=” […]

哪些Java库执行HTTP Accept Header Parsing?

哪些Java库解析HTTP Accept标头?

DefaultHttpClient GET和POST命令Java Android

好的,这是我的申请: 一个Android应用程序,允许我从移动应用程序而不是从网站向CokeZone.co.uk提交CokeZone代码。 所以我写了这段代码来做post post命令,然后检查我是否登录后。 问题是 – 我发送post命令后从主页获取的html是默认的 – 好像我没有登录 – 所以出现了问题。 谁能请帮忙! 它可能是我发送POST的URL,或POST命令中的params – 我还没有完成很多这样的东西,所以它可能是显而易见的。 以下是我目前的代码: DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); thisResponse = printPage(entity.getContent()); Log.e(“debug”,thisResponse); System.out.println(“Login form get: ” + response.getStatusLine()); if (entity != null) { entity.consumeContent(); } System.out.println(“Initial set of cookies:”); […]

如何在Http POST请求中发送图像文件? (Java)的

所以我正在编写一个小应用程序,使用他们提供的API将图像目录转储到用户的tumblr博客中: http : //www.tumblr.com/docs/en/api 我已经发布明文了,但现在我需要找出如何在POST中发送图像文件而不是UTF-8编码的文本,我迷路了。 我的代码目前正在返回403禁止错误,好像用户名和密码不正确(它们不是),而我尝试的其他所有内容都给我一个错误的请求错误。 如果可以的话,我宁愿不必使用外部库。 这是我的ImagePost类: public class ImagePost { String data = null; String enc = “UTF-8”; String type; File img; public ImagePost(String imgPath, String caption, String tags) throws IOException { //Construct data type = “photo”; img = new File(imgPath); data = URLEncoder.encode(“email”, enc) + “=” + URLEncoder.encode(Main.getEmail(), enc); data += “&” […]

从Java中的特定IP生成HttpRequest

我正在使用Apache HttpClient生成Post请求并提交数据。 由于远程应用程序在提交数据的用户的IP地址上进行中继,因此我想发送用户指定IP地址的发布请求。 我该如何配置? public static void loginUser(String username, String password, String ip) throws Exception{ try { HttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“http://login.myapp.com/”); // Request parameters and other properties. List params = new ArrayList(2); params.add(new BasicNameValuePair(“username”,username)); params.add(new BasicNameValuePair(“password”, password)); httppost.setEntity(new UrlEncodedFormEntity(params, “UTF-8”)); // Execute and get the response. HttpResponse response = […]