Android的HttpClient的和HTTPS [英] Android HttpClient and HTTPS

查看:143
本文介绍了Android的HttpClient的和HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来实施的Andr​​oid HTTPS连接。从本质上讲,我试图连接到使用org.apache.http.client.HttpClient的服务器。我相信,在某个时候,我需要访问应用程序的密钥库,以便允许我的客户用私钥。但是,就目前而言,我只是试图连接,看看会发生什么;我不断收到一个HTTP / 1.1 400错误的请求错误。

I'm new to implementing HTTPS connections in Android. Essentially, I'm trying to connect to a server using the org.apache.http.client.HttpClient. I believe, at some point, I'll need to access the application's keystore in order to authorize my client with a private key. But, for the moment, I'm just trying to connect and see what happens; I keep getting an HTTP/1.1 400 Bad Request error.

我似乎无法使头或这个尾巴,尽管许多例子(没有人似乎为我工作)。我的code看起来是这样的(身体常数为XMLRPC):

I can't seem to make heads or tails of this despite many examples (none of them seem to work for me). My code looks like this (the BODY constant is XmlRPC):

 private void connect() throws IOException, URISyntaxException{

    HttpPost post     = new HttpPost(new URI(PROD_URL));
    HttpClient client = new DefaultHttpClient();

    post.setEntity(new StringEntity(BODY));
    HttpResponse result = client.execute(post);

    Log.d("MainActivity", result.getStatusLine().toString());

}

所以,pretty的简单。让我知道是否有任何人有任何意见。谢谢!

So, pretty simple. Let me know if anyone out there has any advice. Thanks!

推荐答案

这应该让你开始。我使用的基本上是一样的,除了与 ThreadSafeClientConnManager

This should get you started. I'm using basically the same, except with ThreadSafeClientConnManager.

SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", 
            SSLSocketFactory.getSocketFactory(), 443));

HttpParams params = new BasicHttpParams();

SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);

HttpClient client = new DefaultHttpClient(mgr, params);

这篇关于Android的HttpClient的和HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆