带有.pfx证书的Vapor的POST请求

我正在尝试使用Vapor编写服务器,该服务器与另一台服务器通信。 在来电/ auth上,我需要调用另一台服务器,该服务器要求使用证书对请求进行签名。 现在,我只想返回状态码和正文。

比方说,该证书名为test_cert.pfx,密码为“ test_pass”。 我该如何附加我的请求才能成功?

router.get("auth") { req -> Future<String> in
    var headers: HTTPHeaders = .init()
    headers.add(name: .contentType,value: "application/json")
    let bodyString = "{\"someKey\": \"someValue\"}"
    let body = HTTPBody(string: bodyString)
    let httpReq = HTTPRequest(
        method: .POST,url: URL(string: "/auth")!,headers: headers,body: body)
    let client = HTTPClient.connect(hostname: "https://server.require.cert.com",on: req)
    let httpRes = client.flatMap(to: HTTPResponse.self) { client in
        return client.send(httpReq)
    }

    let data = httpRes.map(to: String.self) { httpResponse in
        return "\(httpResponse.status.code.description) \(httpResponse.body.description)"
    }
    return data
}

这就是现在发生的事情:

  

[错误] connectFailed(NIO.NIOConnectionError(主机:“ https://server.require.cert.com”,端口:80,dnsAError:可选(NIO.SocketaddressError.unknown(主机:“ https://server.require.cert.com”,端口:80) ),dnsAAAAError:可选(NIO.SocketaddressError.unknown(主机:“ https://server.require.cert.com”,端口:80)),connectionErrors:[]))(ErrorMiddleware.swift:26)   [DEBUG]使ChannelErrorDebuggable以获得更好的调试信息。 (ErrorMiddleware.swift:26)

liuqian125 回答:带有.pfx证书的Vapor的POST请求

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3069606.html

大家都在问