php - Android 模拟器应用程序无法连接到我的本地 mysql 服务器
问题描述
// URL
private final static String base_URL = "http://10.0.2.2:8080/shreemant/fetch_product.php";
RequestQueue queue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delivery);
final TextView txtName = (TextView)findViewById(R.id.txtName);
final TextView txtAddress = (TextView)findViewById(R.id.txtAddress);
queue = Volley.newRequestQueue(this);
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, base_URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
txtName.setText(response.getString("NAME"));
txtAddress.setText(response.getString("ADDRESS"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("error", error.toString());
}
});
queue.add(request);
在 safari 中键入相同的 URL 会显示JSON
我的php
脚本所回显的结构。无法弄清楚为什么它不能在 Android Studio 上运行。方法也试过了Gson
,得到了error parsing TSL header
。错误 非常感谢任何帮助。
这是 Web 浏览器中的输出:
{"ORDER_NO":"1","NAME":"PRITESH GOYAL","PHONE":"9893291225","ADDRESS":"CHOTI GWALTOLI","ORDER_DESC":"COW GHEE - 1 KG - QT -1","AMOUNT":"500","DRIVER":"VINOD","LANDMARK":"PATEL BRIDGE"}
解决方案
推荐阅读
- python-3.x - 为什么打印输出在 DataFrame 到 DataFrameGroupBy 之间没有变化?
- visual-studio - 文件夹权限在使用 VS 2017 编译期间开始修改
- python - Pytesseract 无法识别图像中的数字
- arrays - 如何获取一堆相同大小的二维数组并将它们变成三个维度?
- javascript - 我无法理解这个 useEffect 是如何通过 fetch 运行的
- java - 在中央找不到工件 gnu.trove:trove:jar:3.0.3 (https://repo.maven.apache.org/maven2)
- php - PHP HTML动态创建时间课程表
- javascript - 像 Promise 一样执行 for 循环
- search - Sitecore Solr 搜索完全匹配问题
- python - 是否可以使重新采样中的移动窗口从最近的日期开始?