android — отсутствует обязательный параметр tag, переполнение стека

я получаю эту ошибку Обязательный параметр ‘tag’ отсутствует на тосте android, пожалуйста, помогите, я не могу найти свою ошибку ниже У меня есть код пользователя android и код php сервера выше, я использую библиотеку залпа для httprequests

StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {

@Override
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
// User successfully stored in MySQL
// Now store the user in sqlite
String uid = jObj.getString("uid");

JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user
.getString("created_at");

// Inserting row in users table
db.addUser(name, email, uid, created_at);

// Launch login activity
Intent intent = new Intent(
RegisterActivity.this,
LoginActivity.class);
startActivity(intent);
finish();
} else {

// Error occurred in registration. Get the error
// message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Registration Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
})
{

@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "register");
params.put("name", name);
params.put("email", email);
params.put("password", password);

return params;
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};

// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

}

AppcontrollerClass здесь

public class AppController extends Application {

public static final String TAG = AppController.class.getSimpleName();

private RequestQueue mRequestQueue;

private static AppController mInstance;

@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}

public static synchronized AppController getInstance() {
return mInstance;
}

public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}

return mRequestQueue;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}

это журнал android

  08-07 14:35:36.552  19120-20088/com.example.panos.chatsmartapp D/Volley﹕ [7445] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://192.168.1.3/android_login_api/ 0x355f917 NORMAL 1> [lifetime=3858], [size=65], [rc=200], [retryCount=0]
08-07 14:35:36.662  19120-19120/com.example.panos.chatsmartapp D/RegisterActivity﹕ Register Response: {"error":true,"error_msg":"Required parameter 'tag' is missing!"}
08-07 14:35:36.702  19120-19120/com.example.panos.chatsmartapp D/Toast﹕ checkMirrorLinkEnabled returns : false
08-07 14:35:36.702  19120-19120/com.example.panos.chatsmartapp D/Toast﹕ showing allowed
08-07 14:35:36.702  19120-19120/com.example.panos.chatsmartapp D/Volley﹕ [1] Request.finish: 4253 ms: [ ] http://192.168.1.3/android_login_api/ 0x355f917 NORMAL 1
08-07 14:35:36.712  19120-19120/com.example.panos.chatsmartapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null

это код php

<?php
if (isset($_POST['tag']) && $_POST['tag'] != '') {
// get tag
$tag = $_POST['tag'];

// include db handler
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// response Array
$response = array("tag" => $tag, "error" => FALSE);

// check for tag type
if ($tag == 'login') {
// Request type is check Login
$email = $_POST['email'];
$password = $_POST['password'];

// check for user
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false) {
// user found
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user not found
// echo json with error = 1
$response["error"] = TRUE;
$response["error_msg"] = "Incorrect email or password!";
echo json_encode($response);
}
} else if ($tag == 'register') {
// Request type is Register new user
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];

// check if user is already existed
if ($db->isUserExisted($email)) {
// user is already existed - error response
$response["error"] = TRUE;
$response["error_msg"] = "User already existed";
echo json_encode($response);
} else {
// store user
$user = $db->storeUser($name, $email, $password);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Error occured in Registartion";
echo json_encode($response);
}
}
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknow 'tag' value. It should be either 'login' or 'register'";
echo json_encode($response);
}
}
else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameter 'tag' is missing!";
echo json_encode($response);
}

?>

Myabe у меня проблема со строкой utf8 с помощью json_encode / json_decode, я не знаю …

0

Решение

Что вы можете попробовать, так это создать html-форму с методом post и попытаться нажать на URL. Если ответ верный, это будет означать, что отправка FORM через вызов POST в вашем коде Android неверна.

<html><head>
</head>
<body>
<form name="form" action="index.php" method="post">
<input name="name" type="tezt" value="Porcupine"/>
<input name="tag" type="hidden" value="register"/>
<input name="email" type="text" value="Porcupine@gmail.com"/>
<input name="password" type="password" value=""/>
<input type="submit" value="send">
</form>
</body>

Вы можете использовать это. Замените URL действия соответственно

0

Другие решения

удалить код ниже не нужно

 @Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector