内部https请求不走系统代码
This commit is contained in:
parent
d26fbf9797
commit
c63734960b
@ -33,25 +33,19 @@ struct SDLAPIClient {
|
|||||||
]
|
]
|
||||||
|
|
||||||
static func doPost<T: Decodable>(path: String, params: [String: Any], as: T.Type) async throws -> T {
|
static func doPost<T: Decodable>(path: String, params: [String: Any], as: T.Type) async throws -> T {
|
||||||
let config = URLSessionConfiguration.default
|
let config = URLSessionConfiguration.ephemeral
|
||||||
config.connectionProxyDictionary = [
|
config.connectionProxyDictionary = [:]
|
||||||
kCFNetworkProxiesHTTPEnable as String: 0,
|
|
||||||
kCFNetworkProxiesHTTPSEnable as String: 0,
|
|
||||||
kCFNetworkProxiesSOCKSEnable as String: 0,
|
|
||||||
kCFNetworkProxiesProxyAutoConfigEnable as String: 0,
|
|
||||||
kCFNetworkProxiesProxyAutoDiscoveryEnable as String: 0
|
|
||||||
]
|
|
||||||
let session = URLSession(configuration: config)
|
let session = URLSession(configuration: config)
|
||||||
|
|
||||||
let postData = try! JSONSerialization.data(withJSONObject: params)
|
let postData = try! JSONSerialization.data(withJSONObject: params)
|
||||||
var request = URLRequest(url: URL(string: baseUrl + path)!)
|
let url = URL(string: baseUrl + path)!
|
||||||
|
var request = URLRequest(url: url)
|
||||||
request.httpMethod = "POST"
|
request.httpMethod = "POST"
|
||||||
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||||
request.addValue(sign(params: params), forHTTPHeaderField: "X-sign")
|
request.addValue(sign(params: params), forHTTPHeaderField: "X-sign")
|
||||||
request.httpBody = postData
|
request.httpBody = postData
|
||||||
|
|
||||||
let (data, _) = try await session.data(for: request)
|
let (data, _) = try await session.data(for: request)
|
||||||
|
|
||||||
if let response = String(bytes: data, encoding: .utf8) {
|
if let response = String(bytes: data, encoding: .utf8) {
|
||||||
NSLog("url: \(path), response is: \(response)")
|
NSLog("url: \(path), response is: \(response)")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user