我使用两种方法尝试使用HTTPS URL:
具有正确值的旧的已弃用和返回响应.
这是代码,它不需要忽略ssl证书它自己忽略它或可能使用其他技术:
public String newApiPost(String url,String p1,String p2,String p3){
HttpClient httpClient = new DefaultHttpClient();
// replace with your url
HttpPost httpPost = new HttpPost(url);
//Post Data
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>
();
nameValuePair.add(new BasicNameValuePair("cliend_id",p1));
nameValuePair.add(new BasicNameValuePair("client_secret", p2));
nameValuePair.add(new BasicNameValuePair("key",p3));
//Encoding POST data
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// log exception
e.printStackTrace();
}
//making POST request.
try {
HttpResponse response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(httpEntity,
HTTP.UTF_8);
Log.d("response", result);
// write …Run Code Online (Sandbox Code Playgroud) 我成功地将预定义的领域数据库添加到我的应用程序并获取数据
copyBundledRealmFile(this.getResources().openRawResource(R.raw.test),
"test");
RealmConfiguration config1 = new RealmConfiguration.Builder(this)
.name("test")
.schemaVersion(1)
.migration(new Migration())
.build();
realm = Realm.getInstance(config1);
realm.close();
private String copyBundledRealmFile(InputStream inputStream, String outFileName) {
try {
File file = new File(this.getFilesDir(), outFileName);
FileOutputStream outputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, bytesRead);
}
outputStream.close();
return file.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用时如何获取领域实例的问题
realm = Realm.getDefaultInstance();
Run Code Online (Sandbox Code Playgroud)
给我空数据如何在应用程序中获取实例