我已经设置了一个
Perfect服务器并且我已经编写了所有的API,但是我仍然坚持使用CURL,我不知道如何设置我之前从未使用过CURL的头文件.
我正在设置支付网关,我想设置授权标题并发送正文数据,但我不知道如何.
从例证http://perfect.org/docs/cURL.html
let curlObject = CURL(url: "http://www.perfect.org") curlObject.perform { code,header,body in print("Request error code \(code)") print("Response: \(curlObject.responseCode)") print("Header: \(header)") print("Body: \(body)") }
我提到这个却没有帮助怎么办?
解决方法
经过大量的搜索,我找到了一些东西
let url = "https://httpbin.org/post" let postParamString = "key1=value1&key2=value2" let byteArray = [UInt8](postParamString.utf8) let curl = CURL(url: url) let _ = curl.setoption(CURLOPT_POST,int: 1) let _ = curl.setoption(CURLOPT_POSTFIELDS,v: UnsafeMutableRawPointer(mutating: byteArray)) let _ = curl.setoption(CURLOPT_POSTFIELDSIZE,int: byteArray.count) curl.perform { code,body in print("Request error code \(code) \n Response: \(curl.responseCode) \n Header: \(UTF8Encoding.encode(bytes:header)) \n Body: \(UTF8Encoding.encode(bytes: body))") }
有关更多信息,请参阅此C示例
https://curl.haxx.se/libcurl/c/example.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。