找到一个简单的答案让我最终问了。
我需要做什么/添加什么才能发送带有url调用的身份验证?我对此很感兴趣,但就是看不到解决方案。
设置包含必要信息的url,然后进行调用。这是Curl call:
curl -v -X GET https://api.jsecoin.com/v1.7/balance/auth/0/ \
-H "Content-Type: application/json" \
-H "Authorization: JSE API Key"回复示例:
{
"success": 1,
"notification": "Your balance is 99 JSE",
"balance": 99
}这是我在Swift 4,XCode 9.xx iOS 11.4中执行此操作的代码片段,但我不知道如何添加授权。
func makeGetCall() {
// Set up the URL request
//let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
let todoEndpoint: String = "https://api.jsecoin.com/v1.7/balance/auth/0/"
//-H \"Content-Type: application/json\" -H \"Authorization: xxxxxxxxxxxxxxxxx\""
guard let url = URL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = URLRequest(url: url)
// set up the session
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
config.httpAdditionalHeaders = [
"Content-Type": "application/json",
"Authorization": "xxxxxxxxxxxxxxxxxxxxx"
]
// make the request
let task = session.dataTask(with: urlRequest) {
(data, response, error) in
// check for any errors
guard error == nil else {
print("error calling GET on /todos/1")
print(error!)
return
}这会返回
The todo is: ["notification": API Balance Failed: User API key credentials could not be matched, "fail": 1]无法从JSON获取待办事项标题
https://stackoverflow.com/questions/51379707
复制相似问题