完全な作業コードはこちら..
private void LoginUser() {
try {jsonObject.put("password",hashpassword );jsonObject.put("username",username);} catch (JSONException e){e.printStackTrace();}
jsonStr =jsonObject.toString();
//json 文字列変数これは、文字列でデータを送信する生データを保持します ={"username":"your user username","password":"yourpassword"} //
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, SignInUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getBaseContext(),response.toString(), Toast.LENGTH_LONG).show();
hideProgressDialog();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
Toast.makeText(getBaseContext(),error.toString(), Toast.LENGTH_LONG).show();
}
}){
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
@Override
public byte[] getBody() {
try {
return jsonStr == null ? null : jsonStr.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s",
jsonStr, "utf-8");
return null;
}
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String responseString = "";
if (response != null) {
responseString = String.valueOf(response.statusCode);
}
return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
}
@Override
public Map<String,String> getHeaders() throws AuthFailureError {
Map<String,String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}};
requestQueue.add(stringRequest);
}