代码之家  ›  专栏  ›  技术社区  ›  Laurence Wingo

当使用alamofire检查服务器响应时,开括号意味着什么?

  •  0
  • Laurence Wingo  · 技术社区  · 6 年前

    当使用Alamoire进行呼叫时,我想检查服务器的响应。服务器响应,状态代码为400,标题为 但不显示其余信息。这是什么意思?我有很高的倾向认为问题出在我的头部,但我不确定具体是什么。

    class func missionone()。{
    
    让authorizationPath:string=“https://belivedev.restv2.eastus.media.azure.net/api/channels”
    如果让authorizationurl:url=url.init(string:authorizationpath){
    let参数:【字符串:任意】.=[
    “name”:“ios-test-channel-1”,
    “description”:“发现时使用的我的频道说明”,
    “输入”:。[
    “keyframeInterval”:“”,
    “streamingprotocol”:“fragmentedmp4”,
    “accesscontrol”:[“ip”:[“allow”:。[
    [
    “name”:“全部允许”,
    “address”:“0.0.0.0”,
    “SubnetPrefixLength”:“”
    ]
    ]
    “endpoints”:[]
    ,
    “预览”:。[
    “accesscontrol”:[“ip”:[“allow”:。[
    [
    “name”:“全部允许”,
    “address”:“0.0.0.0”,
    “SubnetPrefixLength”:“”
    ]
    ]
    “endpoints”:[]
    ,
    “output”:[“hls”:[“fragmentsPerSegment”:1],
    “CrossSiteAccessPolicies”:。[
    “clientaccesspolicy”:“”,
    “CrossDomainPolicy”:“”
    ]
    ]
    guard let bealertoken=azureMediaServiceSapimaManager.sharedInstance.authtoken else返回
    让标题=[
    “x-ms-version”:“2.15”,
    “accept”:“应用程序/json”,
    “content type”:“应用程序/json”,
    “dataserviceversion”:“3.0”,
    “maxdataserviceversion”:“3.0”,
    “user agent”:“Azure Media Services邮差集合”,
    “授权”:“持票人\(持票人)”,
    “主机”:“https://rest.media.azure.net”
    ]
    alamofile.request(authorizationURL,method:.post,参数:参数,编码:urlencoding.default,头:头)
    .debuglog()。
    .validate(状态代码:200..<300)
    .responseJSON响应
    开关响应结果{
    case.failure(允许错误):
    打印(错误。本地化描述)
    print(“我们点击了failure switch语句\(error.localizedDescription)”)
    print(“发送到服务器的URL请求是:(response.request)”)
    print(“从服务器发送回的响应是:(response.response)”)
    返回
    案例.成功:
    打印(“验证成功”)
    }
    }
    }
    }
    
    }
    

    当使用Alamoire进行呼叫时,我想检查服务器的响应。服务器响应{ status code 400, Headers { 但不显示其余信息。这是什么意思?我有很高的倾向认为问题出在我的头部,但我不确定具体是什么。

    class func missionOne(){
    
            let authorizationPath: String = "https://belivedev.restv2.eastus.media.azure.net/api/Channels"
            if let authorizationURL: URL = URL.init(string: authorizationPath){
                let parameters: [String : Any] = [
                    "Name": "iOS-test-channel-1",
                    "Description": "My channel description for use in discovery",
                    "Input": [
                        "KeyFrameInterval": "",
                        "StreamingProtocol": "FragmentedMP4",
                        "AccessControl": ["IP": ["Allow": [
                            [
                                "Name": "Allow All",
                                "Address": "0.0.0.0",
                                "SubnetPrefixLength": ""
                            ]
                            ]]],
                        "Endpoints": []
                    ],
                    "Preview": [
                        "AccessControl": ["IP": ["Allow": [
                            [
                                "Name": "Allow All",
                                "Address": "0.0.0.0",
                                "SubnetPrefixLength": ""
                            ]
                            ]]],
                        "Endpoints": []
                    ],
                    "Output": ["Hls": ["FragmentsPerSegment": 1]],
                    "CrossSiteAccessPolicies": [
                        "ClientAccessPolicy": "",
                        "CrossDomainPolicy": ""
                    ]
                ]
                guard let bearerToken = AzureMediaServicesAPIManager.sharedInstance.authToken else { return }
                let headers = [
                    "x-ms-version": "2.15",
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "DataServiceVersion": "3.0",
                    "MaxDataServiceVersion": "3.0",
                    "User-Agent": "azure media services postman collection",
                    "Authorization": "Bearer \(bearerToken)",
                    "Host" : "https://rest.media.azure.net"
                ]
                Alamofire.request(authorizationURL, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers)
                    .debugLog()
                    .validate(statusCode: 200..<300)
                    .responseJSON { response in
                        switch response.result {
                        case .failure(let error):
                            print(error.localizedDescription)
                            print("We hit the failure switch statement \(error.localizedDescription)")
                            print("The url request sent to the server is: \(response.request)")
                            print("The response sent back from the server is: \(response.response)")
                            return
                        case .success:
                            print("Validation Successful")
                            }
                        }
                }
        }
    
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Craig Siemens    6 年前

    the response description