Android的:从一个HTTPS URL响应 [英] Android: Get response from a https url
问题描述
问候,
我开发一个Android应用程序,需要打开一个URL(与POST参数)通过https,并获得响应。
I'm developing an Android app and need to open a url (with POST parameters) over https and get the response.
还有更加复杂,我有一个自签名证书。我也需要接受Cookie。
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?
在预先感谢,
推荐答案
我设法得到这一切与cookies和无符号的HTTPS工作asyncronously。
I managed to get it all working asyncronously with both cookies and unsigned https.
我用code在这里:
的http://masl.cis.gvsu.edu/2010/04/05/android-$c$c-sample-asynchronous-http-connections/
和修改可使用布赖恩Yarger的code此处无符号的https:
and modified for unsigned https using Brian Yarger's code here:
(添加上述code在HttpConnection.java的run()的开头)
(Add the above code to the beginning of run() in HttpConnection.java)
要拿到饼干的工作,我不得不修改一些code(POST从HttpConnection.java片段):
To get the cookies to work, I had to modify some code (POST snippet from HttpConnection.java):
case POST:
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(data));
httpPost.addHeader("Cookie", Cookie.getCookie());
response = httpClient.execute(httpPost);
Header[] headers=response.getAllHeaders();
for(int i=0;i<headers.length;i++){
if(headers[i].getName().equalsIgnoreCase("Set-Cookie")){
//Log.i("i",headers[i].getName()+"---"+headers[i].getValue());
Cookie.setCookie(headers[i].getValue());
break;
}
}
break;
非常感谢大家对我指点的方向,
Many thanks to everyone for pointing me in the direction,
这篇关于Android的:从一个HTTPS URL响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!