using URLSession working fine but as i need to use proxy i decide to try async-http-client
let data = NSMutableData(data: "username=\(emailText)".data(using: .utf8)!)
data.append("&password=\(encriptedPassword)".data(using: .utf8)!)
data.append("&missioncode=code".data(using: .utf8)!)
data.append("&countrycode=code".data(using: .utf8)!)
data.append("&captcha_version=value".data(using: .utf8)!)
data.append("&captcha_api_key=\(token)".data(using: .utf8)!)
var request = URLRequest(url: login)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = data as Data
working fine
with NSMutableData working fine but with AHC i try it was not working
// Prepare your request body as Data
let lp = LoginPayload(username: emailText, password: vfsPassword, missioncode: "code", countrycode: "code", captcha_api_key: token)
let data = lp.toURLEncodedFormData().data(using: .utf8)
var buffer = ByteBufferAllocator().buffer(capacity: data!.count)
buffer.writeBytes(data!)
// Construct the request
var request = HTTPClientRequest(url: "link")
request.method = .POST
request.headers = [....]
request.body = .bytes(buffer)
also try send NSMutableData via .bytes(buffer) but not getting sucess getting error 403 Forbidden
only confuse is what this .bytes(buffer) work is it same as URLSesion request body?
https://github.com/swift-server/async-http-client
Попробуй так: let selector = ["selector": ["name": "Greg"]] let bodyData = try JSONEncoder().encode(selector) // Data let body: HTTPClient.Body = .data(bodyData) let request = try HTTPClient.Request( url: url, method: .POST, headers: headers, body: body )
Обсуждают сегодня