我想发送JsonObjectRequest
到Laravel
。但是我面临着这个问题:
E / Volley:[239] BasicNetwork.performRequest:意外的响应代码 http://10.0.2.2:8000/req
为500
我已经在互联网上进行搜索,但是找不到该问题的答案。
我的Java代码:
public void loginUser(String email, String password, final OnLoginResponse onLoginResponse){
JSONObject requestJsonObject=new JSONObject();
try {
requestJsonObject.put("email",email);
requestJsonObject.put("password",password);
JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET, "http://10.0.2.2:8000/req",requestJsonObject , new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
request.setRetryPolicy(new DefaultRetryPolicy(18000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Volley.newRequestQueue(context).add(request);
} catch (JSONException e) {
Log.e(TAG, "loginUser: "+e.toString());
}
}
我的Laravel代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ReqDemoController extends Controller
{
public function getData(Request $request){
$data = $request->json()->all();
$email = $data->input('email');
$pass = $data->input('password');
DB::table('login')->insert([
'email' => $email,
'password' => $pass
]);
}
}