1

I am using simple json basic auth request to api but getting the error code

Xcode - 10.1 Beta Swift 4

My Code

     let username = "Api_Username"
    let password = "Api_Password"
    let loginString = String(format: "%@:%@", username, password)
    let loginData = loginString.data(using: String.Encoding.utf8)!
    let base64LoginString = loginData.base64EncodedString()


    let request = NSMutableURLRequest(url: NSURL(string: "\(BaseUrl)\(taskUrl)")! as URL)
    let session = URLSession.shared
    request.httpMethod = method
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.addValue("application/json", forHTTPHeaderField: "Accept")
    request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")

    let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error -> Void in
        if error != nil {
            print("Error: \(String(describing: error))")
        } else {
            print("Response: \(String(describing: response)) and data is \(data)")

            print("status code is \(((response as? HTTPURLResponse)?.statusCode)!)")

            do {
                if  let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSArray {
                    print("main array count is \(json.count)")
                  self.giftCardView?.responseofGiftCardApiCall(array: json, statusCode: ((response as? HTTPURLResponse)?.statusCode)!)
                }

            } catch {
                print("error")
            }
        }
    })

    task.resume()

    }
}

API response:-

new_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x102788c30] get output frames failed, state 8196 thanks in advance

ravi singh
  • 11
  • 2

0 Answers0