我需要添加我的授权才能在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;
}
那么,如何将授权添加到方法获取请求?
答案 0 :(得分:0)
我不确定您的特定代码发生了什么,但手动设置Authorization标头并不是正确的方法。相反,您应该通过-URLSession来设置会话以处理身份验证质询:task:didReceiveChallenge:completionHandler:delegate callback。