Tag: httpclient

org.apache.http.entity.FileEntity在Android 6(棉花糖)

我将应用程序升级到API 23,其中org.apache.http已弃用。 我目前(不赞成)的代码如下所示: HttpClient httpClient = new DefaultHttpClient(); File file = new File(attr.Value); String url = server_url; HttpPost request = new HttpPost(url); FileEntity fileEntity = new FileEntity(file, "image/png"); request.setEntity(fileEntity); HttpResponse response = httpClient.execute(request); String output = getContent(response.getEntity().getContent()); 我已经find了一些如何使用HttpURLConnection完成这些build议的build议,但是它们HttpURLConnection当前的解决scheme(不能再使用)要复杂得多。 我正在谈论执行与上面相同的function的许多代码行。 例子是: 这个页面和这个页面 有没有人有一个很好的固体更短的解决scheme呢?

如何使用Java HttpClient库使用PHP上传文件

我想编写Java应用程序,它将使用PHP将file upload到Apache服务器。 Java代码使用Jakarta HttpClient库4.0版beta2: import java.io.File; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.FileEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.CoreProtocolPNames; import org.apache.http.util.EntityUtils; public class PostFile { public static void main(String[] args) throws Exception { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("http://localhost:9002/upload.php"); File file = new File("c:/TRASH/zaba_1.jpg"); FileEntity reqEntity […]

在Android上接受HTTP的证书

我正在尝试使用HttpClient在Android手机上build立Https连接。 麻烦的是,因为证书没有签名,我不断收到“javax.net.ssl.SSLException:不受信任的服务器证书”。 现在我已经看到了一系列解决scheme,您只需接受所有证书,但如果我想问用户呢? 我想得到一个类似于浏览器的对话框,让用户决定是否继续。 最好我想使用浏览器相同的certificatestore。 有任何想法吗?

使用HttpClient通过HTTPS信任所有证书

最近在Https上发布了一个关于HttpClient的问题( 在这里find )。 我已经取得了一些进展,但是我遇到了新的问题。 和我最后一个问题一样,我似乎无法在任何地方find适合我的例子。 基本上,我希望我的客户端接受任何证书(因为我只是指向一台服务器),但我不断得到一个javax.net.ssl.SSLException: Not trusted server certificate exception. 所以这就是我所拥有的: public void connect() throws A_WHOLE_BUNCH_OF_EXCEPTIONS { HttpPost post = new HttpPost(new URI(PROD_URL)); post.setEntity(new StringEntity(BODY)); KeyStore trusted = KeyStore.getInstance("BKS"); trusted.load(null, "".toCharArray()); SSLSocketFactory sslf = new SSLSocketFactory(trusted); sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme ("https", sslf, 443)); SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), schemeRegistry); HttpClient […]