3
私は端末からローカルにRest APIを呼び出していました。これは、以下のようなものだった:Alamofireを使用して不正なリクエスト(ステータスコード400)のjsonデータを読み取る方法
http -v -f --timeout=60 GET 'http://localhost:8080/api/v1/public/users/[email protected]&password=mypassword'
それは出力以下戻っている:
GET /api/v1/public/users/[email protected]&password=mypassword HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8080
User-Agent: HTTPie/0.8.0
HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Mon, 28 Mar 2016 16:59:08 GMT
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Sun, 27- Mar-2016 16:59:13 GMT
Transfer-Encoding: chunked
{
"debugMessage": "Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - [email protected], rememberMe=true] did not match the expected credentials.Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - [email protected], rememberMe=true] did not match the expected credentials.: The subject was expected to be true, but was false",
"errorCode": "INCORRECT_CREDENTIALS",
"logId": "50a695c1a81e0542",
"stackTrace": "org.niopack.r.....
}
は今、私はAlamofireを使用して、このJSONデータを読みたいです。私は以下のようにresponseJSONシリアライザを試してみました:
Alamofire.request(method, urlString, parameters: parameters, encoding: .URL, headers: cookieHeader)
.validate()
.responseJSON {
alamofireResponse in
let jsonData = alamofireResponse.result.value
}
しかし、これはnsonとしてjsonDataを取得しています。もしあなたがいたらあなたは何をするでしょう?
ありがとうございました。