gpt4 book ai didi

java - 我无法发布 com.android.volley.ServerError

转载 作者:行者123 更新时间:2023-12-01 22:17:09 26 4
gpt4 key购买 nike

我尝试仅使用此代码发布我的 php 脚本,但出现服务器错误像这样

private static  final String URL1 = "https://exp.com/appLoc.php";

private void User_Enter(){
StringRequest strRequest1 = new StringRequest(Request.Method.POST, URL1,
new Response.Listener<String>(){
@Override
public void onResponse(String response){

}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String, String> getParams(){
Map<String, String> params1 = new HashMap<String, String> ();

params1.put ("location",la+","+lo);
params1.put ("licence",shpref.getString (Current_user,null));`like so`
params1.put ("main","enter");



return params1;
}
};

queue.add(strRequest1);

}

最佳答案

嗨,您可能在服务器端解码错误时遇到错误,这是什么类型的错误,请使用此

 public void ShowResponse_Error(VolleyError error, Context context) {

if (error instanceof NetworkError) {

Toast.makeText(context,
context.getString(R.string.internet_error),
Toast.LENGTH_LONG).show();

} else if (error instanceof TimeoutError || error instanceof NoConnectionError) {
Toast.makeText(context,
context.getString(R.string.timeout_error),
Toast.LENGTH_LONG).show();
} else if (error instanceof AuthFailureError) {
Toast.makeText(context,
context.getString(R.string.auth_error),
Toast.LENGTH_LONG).show();
} else if (error instanceof ServerError) {

DecodeError(context, error);


}
}

private static void DecodeError(Context context, VolleyError error) {
NetworkResponse response = error.networkResponse;
try {
String res = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
Toast.makeText(context,
obj.getString("message"),
Toast.LENGTH_LONG).show();

} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
e1.printStackTrace();
} catch (JSONException e2) {
// returned data is not JSONObject?
e2.printStackTrace();
}
}

在 String res 中你会得到错误。

关于java - 我无法发布 com.android.volley.ServerError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618085/

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