gpt4 book ai didi

ios - NSURLSession 返回与浏览器不同的响应,为什么?

转载 作者:行者123 更新时间:2023-12-01 15:44:54 25 4
gpt4 key购买 nike

知道为什么 NSURLSession 返回这个响应:

The authorization type you provided is not supported. Only Basic and OAuth are supported

let username = "8r6nibK8Pe28WFhjTX1gGb1Rhhhc7xM02v7XKRPedL4"
let password = "8r6nibK8Pe28WFhjTX1gGb1Rhhhc7xM02v7XKRPedL4"
let loginString = NSString(format: "%@:%@", username, password)
let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64LoginString = loginData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)

let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let authString = "Basic \(base64LoginString)"
config.HTTPAdditionalHeaders = ["Authorization" : authString]

let url = NSURL(string: "https://api.datamarket.azure.com/Bing/Search/Image?$format=json&Query='Rambo'+'Oscar'")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"

let a = NSURLSession(configuration: config).dataTaskWithRequest(request, completionHandler: {data, urlResponse, error in

if data != nil {

let str = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(str)
} else {
_ = 7
}
})

a.resume()

浏览器返回带有有意义图像信息的不同响应。我正在使用基本身份验证来发送请求。

最佳答案

问题可能是选项:.Encoding64CharacterLineLength。尝试:

let base64LoginString = loginData.base64EncodedStringWithOptions([])

调查使用Charles Proxy查看请求的差异。 – zaph 10 分钟前

关于ios - NSURLSession 返回与浏览器不同的响应,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32907981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com