我正在尝试通过我正在开发的android应用程序中的mongolabs REST接口连接到mongodb,但它没有连接,而是抛出异常(或者至少我认为是)。我对后端不熟悉,所以如果我犯了一个致命的菜鸟错误,请原谅我。这是日志猫
01-10 16:28:50.377: W/System.err(630): javax.net.ssl.SSLException: 证书中的主机名不匹配:!= OR OR >01-10 16:28:50.377: W/ System.err(630): at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185) 01-10 >16:28:50.388: W/System.err(630): at org. apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
下面是我编写的用于访问数据库并获取名称等项目的 MongoLabHelper 类的一部分
HttpClient client;
JSONObject db;
MongoLabHelper() throws ClientProtocolException, IOException, JSONException{
client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://api.mongolab.com/api/1/databases/breadcrumbs/collections/crumbs?apiKey=xxxxxxxxxxxxx");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
String json = in.toString();
db = new JSONObject(json);
}
public String getName(String name) throws JSONException {
JSONObject doc = db.getJSONObject(name);
return doc.getString("name");
}
这是它使用的类的一部分
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String name = "Crumb Not Available";
MongoLabHelper help;
try {
help = new MongoLabHelper();
name = help.getName("Chipotle");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.breadcrumb);
TextView crumbName = (TextView) findViewById(R.id.crumb_name);
crumbName.setText(name);