ist 3.2.0 Ich bin mit okHttp und hier ist der Code für Objektanforderung Gebäudewie Antworttext in okhttp zu erhalten, wenn Code 401
MediaType JSON = MediaType.parse(AppConstants.CONTENT_TYPE_VALUE_JSON);
RequestBody body = RequestBody.create(JSON, requestBody);
HttpUrl url = new HttpUrl.Builder()
.scheme("http")
.host("192.168.0.104")
.port(8080)
.addPathSegment("mutterfly-server")
.addPathSegment("j_spring_security_check")
.addQueryParameter("j_username", jsonObject.getString("emailId"))
.addQueryParameter("j_password", jsonObject.getString("password"))
.build();
request = new Request.Builder()
.addHeader(AppConstants.CONTENT_TYPE_LABEL, AppConstants.CONTENT_TYPE_VALUE_JSON)
.addHeader(AppConstants.ACCEPT_LABEL, AppConstants.CONTENT_TYPE_VALUE_JSON)
.url(url)
.post(body)
.build();
Und hier ist, wie ich die Antwort
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
String respBody;
if (response.isSuccessful()) {
if (response.body() != null) {
respBody = response.body().string();
Log.i(TAG, respBody);
response.body().close();
if (AppMethods.checkIfNull(loginParserListener)) {
try {
final VUser user = AppMethods.getGsonInstance().fromJson(respBody, VUser.class);
} catch (Exception e) {
}
}
}
} else {
switch (response.code()){
case 401:
String body="HTTP_UNAUTHORIZED";
break;
}
}
}
});
analysieren
Dies ist die ideale Antwort (vom Web Rest Client), wenn die Authentifizierung fehlgeschlagen ist.
{"msgDesc":"The username or password you entered is incorrect..","statusCode":401}
EDIT:
response.toString()
kehrt
Response{protocol=http/1.1, code=401, message=Unauthorized, url=http://192.168.0.104:8080/mutterfly-server/[email protected]&j_password=1}
response.body().toString()
kehrt
[email protected]
i die 'msgDesc' holen will, die in Reaktion Körper ist. Gibt es irgendeine Methode, die diese Zeichenfolge zurückgibt?
response.toString() gibt Response {Protokoll = http/1.1, Code = 401 , message = Nicht autorisiert, url = http: //192.168.0.104: 8080/mutterfly-server/j_spring_security_check? [email protected]&j_password=1} –
Überprüfen Sie die aktualisierte Antwort –
danke für die Antwort, aber ich habe den Beitrag mit bearbeitet die Antwort überprüfen, dass –