如何在方法Get Request swift中添加授权

时间:2017-04-21 04:07:44

标签: ios swift get

我需要添加我的授权才能在Get方法中获取API。

我已经编码了这样的授权:

/*simple implementation of decimal to hexdecimal
  algorithm is as follows:
  1. take the number and do floor division of 16
  2. write down the remainder
  3. repeat step 1 and 2 with the number from obtained from integer division
  4. when the resulting number is 0, the function returns
*/

#include<iostream>
#include<string>
#include<stdio.h>

using namespace std;

void printHex(int i){
    if(i == 0){
        return;
    }

    int rem = i % 16;
    switch(rem) {
        case 10: cout << "A"; break;
        case 11: cout << "B"; break;
        case 12: cout << "C"; break;
        case 13: cout << "D"; break;
        case 14: cout << "E"; break;
        case 15: cout << "F"; break;
        default: cout << rem; break;
    }

    printHex(i/16);
}

int main(){
    printHex(666);

    return 0;
}

那么,如何将授权添加到方法获取请求?

1 个答案:

答案 0 :(得分:0)

我不确定您的特定代码发生了什么,但手动设置Authorization标头并不是正确的方法。相反,您应该通过-URLSession来设置会话以处理身份验证质询:task:didReceiveChallenge:completionHandler:delegate callback。