请求期间的API错误

时间:2018-01-02 11:56:47

标签: swift alamofire

尝试让API请求起作用,我是初学者,我没有看到问题。

let tron = TRON(baseURL: "https://shopicruit.myshopify.com")

class Home: JSONDecodable {
    let title: String
    let body_html: String
    required init(json: JSON) throws {
        title = json["products"]["title"].stringValue
        body_html = json["products"]["body_html"].stringValue
    }
}

class JSONError: JSONDecodable {
    required init(json: JSON) throws {

    }
}

fileprivate func loadHomeFeed() {

    let request: APIRequest<Home,JSONError> = tron.swiftyJSON.request("/admin/products.json?page=1&access_token=c32313df0d0ef512ca64d5b336a0d7c6")
    request.method = .get
    request.perform(withSuccess: { (Home) in
        print("Successful fetch")
    })
    { (err) in
        print("Failed fetch: ", err)
    }

}

我正在使用TRON(https://github.com/MLSDev/TRON/blob/master/Docs/4.0%20Migration%20Guide.md),它是Alamofire的框架,使用起来似乎很简单。我无法得到我的要求。我收到以下错误:

Failed fetch:  APIError<JSONError>(request: Optional(https://shopicruit.myshopify.com/admin/products.json%3Fpage=1&access_token=c32313df0d0ef512ca64d5b336a0d7c6), response: Optional(<NSHTTPURLResponse: 0x60000003a360> { URL: https://shopicruit.myshopify.com/admin/auth/login } { status code: 200, headers {
    "Cache-Control" = "no-cache, no-store";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Security-Policy" = "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://js-agent.newrelic.com https://bam.nr-data.net https://www.google.com https://www.gstatic.com https://v.shopify.com 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=login&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fauth&source%5Bsection%5D=admin&source%5Buuid%5D=2d566b02-16a0-4bca-bf36-89aa6f8d26bf";
    "Content-Type" = "text/html; charset=utf-8";
    Date = "Tue, 02 Jan 2018 11:37:23 GMT";
    P3P = "CP=\"NOI DSP COR NID ADMa OPTa OUR NOR\"";
    "Referrer-Policy" = "origin-when-cross-origin";
    Server = nginx;
    "Shopify-Auth-Mechanisms" = password;
    "Strict-Transport-Security" = "max-age=7889238";
    "Transfer-Encoding" = Identity;
    Vary = "Accept-Encoding";
    "X-Content-Type-Options" = "nosniff, nosniff";
    "X-Dc" = chi2;
    "X-Download-Options" = noopen;
    "X-Frame-Options" = DENY;
    "X-Permitted-Cross-Domain-Policies" = none;
    "X-Request-Id" = "2d566b02-16a0-4bca-bf36-89aa6f8d26bf";
    "X-ShardId" = 2;
    "X-ShopId" = 10007970;
    "X-Shopify-Login-Required" = true;
    "X-Sorting-Hat-PodId" = 2;
    "X-Sorting-Hat-PodId-Cached" = 1;
    "X-Sorting-Hat-Section" = pod;
    "X-Sorting-Hat-ShopId" = 10007970;
    "X-Sorting-Hat-ShopId-Cached" = 1;
    "X-XSS-Protection" = "1; mode=block; report=/xss-report?source%5Baction%5D=login&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fauth&source%5Bsection%5D=admin&source%5Buuid%5D=2d566b02-16a0-4bca-bf36-89aa6f8d26bf";
} }), data: Optional(13263 bytes), error: Optional(Alamofire.AFError.responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType(acceptableContentTypes: ["application/json"], responseContentType: "text/html"))), errorModel: Optional(Shopify_Product_Page.HomeDatasourceController.JSONError))

0 个答案:

没有答案