php - 通过 PHP 从 android 读取字符串返回 'null'
问题描述
我是 Android 的新手。我阅读了很多关于这个主题的文章,但它们没有帮助。
我创建了一个 PHP 页面来检查登录状态:
<?php
require_once 'wp-load.php';
global $current_user;
$current_user = wp_get_current_user();
//var_dump($current_user->ID);
//var_dump($current_user->display_name);
//var_dump($_COOKIE);
$newURL = "";
if ( !function_exists( 'is_user_logged_in' ) ) {
require_once 'wp-includes/pluggable.php';
}
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
$newURL = "no";
echo $newURL;
} else {
// Logged in.
$newURL = "si";
echo $newURL;
}
?>
我在 Android 中读取了字符串:
try {
url3 = new URL("https://example.com/lg.php");
is = url3.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
Log.d("YourTag", line);
}
} catch (Exception mue) {
mue.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
// Menu part 2
nv = (NavigationView)findViewById(R.id.nv);
if (line == "no") {
nv.getMenu().findItem(R.id.login).setVisible(true);
nv.getMenu().findItem(R.id.logout).setVisible(false);
Toast.makeText(context,"No.",Toast.LENGTH_LONG).show();
} else if (line == "si") {
nv.getMenu().findItem(R.id.login).setVisible(false);
nv.getMenu().findItem(R.id.logout).setVisible(true);
Toast.makeText(context,"Si.",Toast.LENGTH_LONG).show();
}
问题是line
变量为空,因此if
不起作用。有任何想法吗?
解决方案
推荐阅读
- r - 在读取 sas 文件以触发或将数据拉到 r 会话时,有没有办法设置字符编码?
- python-3.x - 从停用词中清除多个术语
- python - tf.keras.layers.Conv3DTranspose 在输入动态形状时抛出 TypeError
- html - 如何在 Symfony 4 表单中的输入上添加占位符?
- python - 删除对象而不刷新django
- amazon-web-services - 对 S3 存储桶中新对象的 PUTS 写后读一致性的警告
- javascript - 当输入、选择等形式发生变化时如何获取计数器?
- node.js - 如何在线正确上传 localhost 网站?
- powershell - 如何比较文件中的两个连续字符串
- cordova - Ionic 4 不能在没有 cordova 的情况下使用 HTTP 插件了吗?