gpt4 book ai didi

android - BasicNetwork.performRequest : Unexpected response code 500 for http://192. 168.1.195:85/tranxavApi/public/api/signup

转载 作者:行者123 更新时间:2023-11-29 02:33:57 27 4
gpt4 key购买 nike

也许这个问题之前已经发布过,但它并没有解决我的问题。我正在尝试使用 laravel 作为后端将数据从 android 发送到 mysql 数据库。我开发了restful Api。这是我的代码。

         try {
RequestQueue requestQueue = Volley.newRequestQueue(SignUpActivity.this);

JSONObject jsonBody = new JSONObject();
jsonBody.put("username","amz");
jsonBody.put("email","amz@gmail.com");
jsonBody.put("password","fashion");
jsonBody.put("vCode","12345");
jsonBody.put("type","coupons");
final String requestBody = jsonBody.toString();

StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("VOLLEY", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
}
}) {
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}

@Override
public byte[] getBody() throws AuthFailureError {
try {
return requestBody == null ? null : requestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8");
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String responseString = "";
if (response != null) {
responseString = String.valueOf(response.statusCode);
// can get more details such as response.headers
}
return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
}
};
requestQueue.add(stringRequest);
} catch (JSONException e) {
e.printStackTrace();
}

API 网址

http://192.168.1.195:85/tranxavApi/public/api/signup

E/VOLLEY: com.android.volley.NetworkError

Laravel 代码

 public function signUp(Request $request){
$success = "Successful";
$validator = Validator::make($request->all(), [
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:5'
]);

if ($validator->fails()){
return response()->json(['error'=>$validator->errors()], 401);
}
User::create([
'email' => $request->get('email'),
'username' => $request->get('username'),
'password' => Hash::make($request->get('password')),
'vCode' => $request->get('vCode')
]);

return response()->json(['success'=> $success], $this->successStatus);
}

我的错误日志

E/Volley: [164] BasicNetwork.performRequest: Unexpected response code 500 for http://192.168.1.195:85/tranxavApi/public/api/signup

E/VOLLEY: com.android.volley.NetworkError

无需授权。非常感谢您的所有回答

最佳答案

将此添加到您的代码中

{     
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json");
params.put("Accept", "application/json");

return params;
}
};

关于android - BasicNetwork.performRequest : Unexpected response code 500 for http://192. 168.1.195:85/tranxavApi/public/api/signup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48112869/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com