我希望能够使用我的用户名/密码使用java代码登录到HTTPS网站(如Gmail)。 我尝试过使用我自己的代码和HTTPClient包(两者都允许我登录到正常的网站(如Facebook)),但不能访问HTTPS网站。 有人能告诉我使用java登录https网站需要什么吗? Thanks!
I want to be able to log into HTTPS websites(like gmail) with my username/password using java code. I've tried using both my own code and the HTTPClient package(both allowed me to log into normal websites( like facebook)), but not into HTTPS websites. Can someone tell me what is necessary to use java to sign into a https website? Thanks!
示例代码:
Example Code:
import org.apache.http.*; import org.apache.http.auth.*; import org.apache.http.client.methods.*; import org.apache.http.impl.client.*; import org.apache.http.util.*; public class ClientAuthentication { public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try { httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("email@gmail", "password")); HttpGet httpget = new HttpGet("www.google/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&ss=1&scc=1<mpl=default<mplcache=2&hl=en&from=logout"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); entity.writeTo(System.out); } EntityUtils.consume(entity); } finally { httpclient.getConnectionManager().shutdown(); } } }推荐答案
您正在谈论身份验证或连接到https服务器(没有客户端身份验证)? 许多网站(如谷歌,脸谱)使用OAuth或OpenID - 阅读它。 如果它的其他东西(比如你只是使用POST)。问题是什么?你是否得到堆栈跟踪?
You are talking about authentication or connecting to https server (without client auth)? Many sites (such as google, facebook) uses OAuth or OpenID - read about it. If its sth else (like you are using simply POST). What is the problem? Are you getting stacktrace?
更多推荐
如何使用Java登录到HTTPS网站?
发布评论