连接/验证安全基于XML的Ruby-on-Rails网站时遇到的问题

时间:2015-11-13 10:47:50

标签: java android ruby-on-rails xml

我在连接基于XML的Ruby-on-Rails网站时遇到了很大的麻烦。

我尝试了多种方法,但不管我总是遇到一个或另一个问题。

我需要的是连接到网站,POST登录名和密码,然后从网站获取返回值(以查看登录是否成功)。它将在某个时候成为一个Android应用程序,但在开始时,我只是希望它在Java中工作。

我当前没有工作的方法就是这样(隐藏IP 道歉):

public static void connect() {
    @SuppressWarnings({ "deprecation", "resource" })
    HttpClient httpClient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost("https://93...145/login");

    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
    nameValuePair.add(new BasicNameValuePair("LOGIN", "name"));
    nameValuePair.add(new BasicNameValuePair("PASSWORD", "password"));


    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    try {
        HttpResponse response = httpClient.execute(httpPost);
        // write response to log
        System.out.println("Http Post Response:" + response.toString());
        // Log.d("Http Post Response:", response.toString());
    } catch (ClientProtocolException e) {
        // Log exception
        e.printStackTrace();
    } catch (IOException e) {
        // Log exception
        e.printStackTrace();
    }
}

该网站是一个开发服务器,因此我得到了#34;无效证书&#34;打开页面时出现错误消息,这会导致Java中出现更大的问题。我设法生成一个有效的&#34;证书使用方法贴她:

https://blogs.oracle.com/gc/entry/unable_to_find_valid_certification

但后来我又遇到了另一个问题:

javax.net.ssl.SSLException: Certificate for <93...145> doesn't match common name of the certificate subject: dev-...no
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:172)
at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:61)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
at org.apache.http.conn.ssl.SSLSocketFactory.verifyHostname(SSLSocketFactory.java:569)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:544)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:409)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at Tilkobling.connect(Tilkobling.java:133)
at Tilkobling.main(Tilkobling.java:33)

所以基本上,有更简单的方法吗?

我想要做的其实很简单:

  1. 连接到网站
  2. 发布登录详情
  3. 请参阅返回消息(如果登录成功,将使用带有用户信息的XML)
  4. 非常感谢任何输入。

0 个答案:

没有答案