java - Android Volley 在服务器上没有被识别为 POST 与 php
问题描述
我正在使用 volley 将帖子发送到我的服务器。在我的 php 里面 insert.php 我有这样的代码
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//do all post functions
}
else{
//notofication that says its not post
}
这是我的 android 中的凌空代码
String HttpUrl = "http://192.168.30.18/insert.php";
// Creating string request with post method
StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String ServerResponse) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing response message coming from server.
Toast.makeText(CreateAccountOrLoginActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
Log.d("responseSuccess",ServerResponse);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing error message if something goes wrong.
Toast.makeText(CreateAccountOrLoginActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
Log.d("responseFail",volleyError.toString());
}
}) {
@Override
protected Map<String, String> getParams() {
// Creating Map String Params.
Map<String, String> params = new HashMap<String, String>();
// Adding All values to Params.
params.put("title",title);
params.put("name", fname);
params.put("surname", sname);
return params;
}
};
// Creating RequestQueue.
RequestQueue requestQueue = Volley.newRequestQueue(CreateAccountOrLoginActivity.this);
// Adding the StringRequest object into requestQueue.
requestQueue.add(stringRequest);
问题是在运行 android 代码后,它返回 insert.php 的 else 语句中的内容,而不是 if 语句中的内容,这意味着它不会被识别为帖子。我如何解决它以使其在 if 语句中运行
解决方案
推荐阅读
- datetime - 在 azure cosmos db 中的两个日期之间选择行
- javascript - 如何改进这个斯诺克得分应用程序?
- javascript - TypeError:无法读取未定义 API 的属性“ft”
- json - 使用 PowerShell 将 JSON 转换为 plist
- html - 跨 2 行垂直对齐长按钮
- ruby - Ruby on rails、Solidus 电子商务、谷歌索引问题
- reactjs - 如何从material-ui延迟渲染选择组件
- html - Selenium VBA 找不到元素
- java - 输出未显示在我的设备上(Android Studio)
- excel - 通过 VBA 在 Excel 中复制单元格公式