2
これは私のJSON体である:Okhttpでオブジェクトを渡してPOSTリクエストを作成するには?
Username username = new Username("IN" , "9620494812");
JSONObject postData = new JSONObject();
try {
postData.put("username" , username);
postData.put("password" , "119209");
} catch (JSONException e) {
e.printStackTrace();
}
RequestBody body = RequestBody.create(MEDIA_TYPE , postData.toString());
Request request = new Request.Builder().url("https://www.gruppie.in/api/v1/login")
.method("POST" , body).build();
私は要求を確認しているが、私はまだ
としてエラーが発生します:次のように私はOkhttp
でPOSTリクエストを作成しようとしている
{
"username": {
"country": "IN",
"number": "9620494812"
},
"password": "119209"
}
応答は次のとおりです。
{"status":401,"type":"about:blank","title":"Unauthorized"}
何私はここで間違っていますか?
https://stackoverflow.com/questions/34179922/okhttp-post-body-as-json答えを –