Android:从 https url 获取响应
您好,
我正在开发一个 Android 应用程序,需要通过 https 打开一个 url(带有 POST 参数)并获取响应。
我有一个自签名证书,这让情况更加复杂。我还需要接受cookies。
有人知道从哪里开始吗?
预先非常感谢,
Greetings,
I'm developing an Android app and need to open a url (with POST parameters) over https and get the response.
There's the added complication that I have a self-signed certificate. I also need to accept cookies.
Anyone have any ideas about where to get started?
Many thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 附带了 apache commons http 库。
设置 https post 请求非常简单:
Android 使用 commons http 库的 4.x 版本,因为 4.0 以下的所有版本都已超出其生命周期。
我无法准确说明如何将自签名证书注册到 HttpClient,但我的公共 http 文档会有所帮助:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
Android comes with the apache commons http library included.
Setting up a https post request is quite easy:
Android uses a version 4.x of the commons http library as all versions below 4.0 are out of their lifecycle.
I can't tell exactly how to register a self-signed certificate to the HttpClient, but mybe the commons http documentation helps:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
我设法使用 cookie 和未签名的 https 使其全部异步工作。
我在这里使用了代码:
http ://masl.cis.gvsu.edu/2010/04/05/android-code-sample-asynchronous-http-connections/
并使用 Brian Yarger 的代码修改为未签名的 https:
Android 上的自签名 SSL 接受
(将上述代码添加到 HttpConnection.java 中 run() 的开头)
为了让 cookies 工作,我必须修改一些代码(来自 HttpConnection.java 的 POST 片段):
非常感谢大家为我指明了方向,
I managed to get it all working asyncronously with both cookies and unsigned https.
I used the code here:
http://masl.cis.gvsu.edu/2010/04/05/android-code-sample-asynchronous-http-connections/
and modified for unsigned https using Brian Yarger's code here:
Self-signed SSL acceptance on Android
(Add the above code to the beginning of run() in HttpConnection.java)
To get the cookies to work, I had to modify some code (POST snippet from HttpConnection.java):
Many thanks to everyone for pointing me in the direction,