Tag: http

HTTPClient-1.4.2:自定义SSL上下文示例所需的说明

这是来自HttpClient-4.x文档的自定义SSL上下文的示例: http : //hc.apache.org/httpcomponents-client-ga/examples.html 注意:为简洁起见,删除注释。 package org.apache.http.examples.client; import java.io.File; import java.io.FileInputStream; import java.security.KeyStore; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; /** * This example demonstrates how to create secure connections with a custom SSL * context. */ public class ClientCustomSSL { public final static void main(String[] args) throws […]

Apache Camel http到http路由(有可能吗?)

我现在开始与Camel。 我见过http客户端的http4组件和http服务器的jetty组件。 我见过几个使用其中一个的例子。 我想知道是否可以将它们组合在一起。 例 from(“jetty:http://0.0.0.0:8080/myapp/myservice”) .to(“http4://www.google.com”); 这将使骆驼成为一个简单的基于http的路由器/代理。 Web浏览器会点击骆驼url而不是google。 (谷歌只是一个例子,我有一个真正的基于POST的服务,我想使用) 这条路线可行吗? 我应该研究Camel还是我需要一个不同的软件框架? 将来我还需要在两者之间添加转换/filter​​。 我试过它并获得了一个nullpointerexception [qtp757856402-14] SendProcessor DEBUG >>>> Endpoint[http4://www.google.com] Exchange[Message: [Body is instance of java.io.InputStream]] [qtp757856402-14] DefaultErrorHandler DEBUG Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. On delivery attempt: 0 caught: java.lang.NullPointerException [qtp757856402-14] DefaultErrorHandler ERROR Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException java.lang.NullPointerException

CookieManager用于多个线程

我试图通过线程建立多个连接。 但是每个连接似乎都会覆盖其他连接,导致连接使用错误的cookie。 在线程类的构造函数内: manager = new CookieManager(); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); 有没有办法管理每个线程或每个类的cookie? 新的失败尝试: 现在每个线程都使用它自己的索引,但它们似乎仍然以cookie方式覆盖彼此。 有任何想法吗? public class threadedCookieStore implements CookieStore, Runnable { CookieStore[] store = new CookieStore[1000]; int index; public threadedCookieStore(int new_index) { index = new_index; // get the default in memory cookie store store[index] = new CookieManager().getCookieStore(); // todo: read in cookies from persistant storage // […]

https会话和发布问题

我有一个应用程序,需要能够通过身份validation请求发送到https,然后发送注册请求。 目前我能够将我的身份validation请求发布到https,它运行正常。 当我尝试将我的注册请求发布到https时,我不断得到服务器响应,说我需要进行身份validation。 在我尝试注册之前,我正在validation。 服务器的管理员说我可能没有保留会话。 我是新手用android和java做的东西。 我是这个https的新手。 我想知道是否有人可以在这里帮助我,我不知道这是肯定的问题,甚至不知道如何在android中保留https会话。 以下是我的代码和任何建议非常感谢!!!! 提前致谢!! //my helper class public class SmartDBHelper { private static Context tThis; private static SmartDBHelper sDBHObject; private static String macAddress; private static String ipAddress; private static HttpsURLConnection https; /* constructor, private prevents any other class from instantiating */ private SmartDBHelper() { } public static synchronized SmartDBHelper […]

是否有适用于Java的简单http响应解析器?

有没有简单的http响应解析器实现? 我们的想法是将完整的响应作为一个大字符串输入,并能够通过界面检索状态码,正文等内容。 请求/响应不是直接通过TCP / IP发送的,因此除了核心rfc 2616解析实现之外不需要任何其他内容。

用java登录网站

我想用java登录一个网站。 我使用的是org.apache.http,我已经写好了 HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(“https://accounts.google.com/ServiceLogin? service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fhl%3Dsl%26tab%3Dwm%26ui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&”); try { List nameValuePairs = new ArrayList(1); nameValuePairs.add(new BasicNameValuePair(“vb_login_username”, “XXX”)); nameValuePairs.add(new BasicNameValuePair(“vb_login_password”, “XXX”)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = “”; while ((line = rd.readLine()) != null) { System.out.println(line); } } catch (IOException e) […]

URLConnection没有得到字符集

我正在使用URL.openConnection()从服务器下载内容。 服务器说 Content-Type: text/plain; charset=utf-8 但是connection.getContentEncoding()返回null 。 怎么了?

Java上的服务器名称指示(SNI)

任何人都可以帮助我开始使用Java中的服务器名称指示进行HTTP连接吗? 我正在尝试从我管理的网站请求内容。 我一直在使用Apache的HttpClient库,但我对安全内容的请求失败,因为网站仅使用SNI进行HTTPS,并且在DefaultHttpClient中未启用SNI。 我已经在Apache的HttpClient库中查找了如何处理这个问题的说明,但我看到最终得到了这个文档: http : //hc.apache.org/httpclient-3.x/sslguide.html ,这已经过时了(当HttpClient和HttpCore是Apache的commons包的一部分时,请参考代码)。 所以…任何帮助?

如何以编程方式测试HTTP连接?

使用Java,我如何测试URL是否可联系,并返回有效的响应? http://stackoverflow.com/about

java.io.IOException:服务器返回HTTP响应代码:403表示URL

我想从url下载mp3文件:“http://upload13.music.qzone.soso.com/30671794.mp3”,我总是得到java.io.IOException:服务器返回HTTP响应代码:403用于URL。 但是使用浏览器打开url时没关系。 以下是我的代码的一部分: BufferedInputStream bis = null; BufferedOutputStream bos = null; try { URL url = new URL(link); URLConnection urlConn = url.openConnection(); urlConn.addRequestProperty(“User-Agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)”); String contentType = urlConn.getContentType(); System.out.println(“contentType:” + contentType); InputStream is = urlConn.getInputStream(); bis = new BufferedInputStream(is, 4 * 1024); bos = new BufferedOutputStream(new FileOutputStream( fileName.toString()));​ 有人可以帮帮我吗? […]