Android Studio,Volley 我没有收到 JSON 回复
Android Studio, Volley I do not get a JSON response
我已经用 Jason Web 令牌构建了一个 laravel Rest API。现在我想制作一个将数据发送到 Web 服务的应用程序。在这里,我首先尝试对自己进行身份验证(使用姓名电子邮件和密码),但我没有得到令牌作为答案。我也没有收到错误,什么也没发生。
private void sendAndRequestResponse() {
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("name", "ida");
jsonBody.put("email", "ida@gmail.com");
jsonBody.put("password", "secret");
final String mRequestBody = jsonBody.toString();
//RequestQueue initialized
mRequestQueue = Volley.newRequestQueue(this);
mJsonRequest = new JsonObjectRequest(
Request.Method.POST, url, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
answer.setText(response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
});
mRequestQueue.add(mJsonRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
您需要启动请求队列才能进行请求调用。
在
之后
mRequestQueue.add(mJsonRequest);
添加关注
mRequestQueue.start();
我已经用 Jason Web 令牌构建了一个 laravel Rest API。现在我想制作一个将数据发送到 Web 服务的应用程序。在这里,我首先尝试对自己进行身份验证(使用姓名电子邮件和密码),但我没有得到令牌作为答案。我也没有收到错误,什么也没发生。
private void sendAndRequestResponse() {
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("name", "ida");
jsonBody.put("email", "ida@gmail.com");
jsonBody.put("password", "secret");
final String mRequestBody = jsonBody.toString();
//RequestQueue initialized
mRequestQueue = Volley.newRequestQueue(this);
mJsonRequest = new JsonObjectRequest(
Request.Method.POST, url, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
answer.setText(response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
});
mRequestQueue.add(mJsonRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
您需要启动请求队列才能进行请求调用。
在
之后mRequestQueue.add(mJsonRequest);
添加关注
mRequestQueue.start();