Android 在Laravel中使用POST方法时出现截击库错误
我正在使用登录/注册系统创建一个应用程序,我正在使用volley库。 当我使用WAMP时,POST方法工作正常,但当我切换到Laravel Homestead时,它给了我一个错误 错误是Android 在Laravel中使用POST方法时出现截击库错误,android,laravel,android-volley,Android,Laravel,Android Volley,我正在使用登录/注册系统创建一个应用程序,我正在使用volley库。 当我使用WAMP时,POST方法工作正常,但当我切换到Laravel Homestead时,它给了我一个错误 错误是 BasicNetwork.performRequest: Unexpected response code 500 我对这个问题做了一些研究,但我很难理解他们的系统。我希望有人能根据我的计划给我一些建议 下面是我的活动的一部分,它从我的php文件中获取响应 MainScreen.java Response.
BasicNetwork.performRequest: Unexpected response code 500
我对这个问题做了一些研究,但我很难理解他们的系统。我希望有人能根据我的计划给我一些建议
下面是我的活动的一部分,它从我的php文件中获取响应
MainScreen.java
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonresposne = new JSONObject(response);
boolean success = jsonresposne.getBoolean("success");
if (success) {
int user_id = jsonresposne.getInt("uid");
Toast.makeText(MainScreen.this,""+user_id,Toast.LENGTH_SHORT).show();
Cart c = new Cart();
c.getUserID(user_id);
Intent intent = new Intent(MainScreen.this, MainActivity.class);
startActivity(intent);
pd.dismiss();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainScreen.this);
builder.setTitle(Html.fromHtml("<font color='#ff0000'>LOGIN FAILED</font>")).setMessage("email and password did not match")
.setCancelable(false)
.setNegativeButton("Ok", null).create().show();
pd.dismiss();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(password, email, responseListener);
RequestQueue queue = Volley.newRequestQueue(MainScreen.this);
queue.add(loginRequest);
}
Response.Listener responseListener=newresponse.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONObject jsonresposne=新的JSONObject(响应);
boolean success=jsonresposne.getBoolean(“success”);
如果(成功){
int user_id=jsonresposne.getInt(“uid”);
Toast.makeText(MainScreen.this,“+user\u id,Toast.LENGTH\u SHORT.show();
购物车c=新购物车();
c、 getUserID(用户id);
意向意向=新意向(MainScreen.this、MainActivity.class);
星触觉(意向);
pd.解散();
}否则{
AlertDialog.Builder=新建AlertDialog.Builder(MainScreen.this);
builder.setTitle(Html.fromHtml(“登录失败”)).setMessage(“电子邮件和密码不匹配”)
.setCancelable(错误)
.setNegativeButton(“确定”,null).create().show();
pd.解散();
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
};
LoginRequest LoginRequest=新的LoginRequest(密码、电子邮件、responseListener);
RequestQueue=Volley.newRequestQueue(MainScreen.this);
添加(loginRequest);
}
这是我的LoginRequest.java
public class LoginRequest extends StringRequest {
private static final String LOGIN_REQUEST_URL = "http://192.168.1.102:8000/app/login";
private Map<String,String> params;
public LoginRequest(String email, String password, Response.Listener<String> listener){
super(Request.Method.POST,LOGIN_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("email",email);
params.put("password",password);
}
@Override
public Map<String, String> getParams() {
return params;
}
公共类LoginRequest扩展了StringRequest{
私有静态最终字符串登录\u请求\u URL=”http://192.168.1.102:8000/app/login";
私有映射参数;
公共登录请求(字符串电子邮件、字符串密码、响应.侦听器){
super(Request.Method.POST,LOGIN\u Request\u URL,listener,null);
params=新的HashMap();
参数put(“电子邮件”,电子邮件);
参数put(“密码”,密码);
}
@凌驾
公共映射getParams(){
返回参数;
}
}
这是我的带有POST方法的php文件
login.php
<?php
$con = mysqli_connect("localhost","homestead","secret","laraveldb");
$email = $_POST["email"];
$password = $_POST["password"];
$statement = mysqli_prepare($con,"SELECT id FROM users WHERE email=? AND password=?");
mysqli_stmt_bind_param($statement,"ss",$password,$email);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement,$id);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["uid"] = $id;
}
echo json_encode($response);
?>
首先检查您的web api是否正常工作,是否使用chrome扩展Advance Rest客户端1
或postman
我的应用程序在WAMP中正常工作。唯一的问题是使用Laravel。我不明白为什么chrome扩展和web api会出现在这里。这些是检查web api是否正常工作的工具。因为服务器端有错误,所以我会试试。但我的大部分研究表明,这是在截击库的POST方法上,如果你使用Laravel,这是一个问题。注意:你的方法与Laravel无关。您应该使用LaravelPassport、JWT等实现至少一个控制器和API中间件。我建议您改型而不是使用Volley(Volley需要很多样板文件)。