I read The Programming Language Swift by Apple in iBooks, but cannot figure out how to make an http request (something like CURL) in Swift. Do I need to import Obj-C classes or do I just need to import default libraries? Or is it not possible to make an HTTP request based on native swift code?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
Check Below Codes :
1. SynchonousRequest
Swift 1.2
Swift 2.0 +
2. AsynchonousRequest
Swift 1.2
Swift 2.0 +
3. As usual URL connection
Swift 1.2
Then
Swift 2.0 +
Then
4. Asynchonous POST Request
Swift 1.2
Swift 2.0 +
5. Asynchonous GET Request
Swift 1.2
Swift 2.0 +
6. Image(File) Upload
Swift 2.0 +
Basic Swift 3 Solution
You can use Just, a
python-requests
style HTTP library.Some example of sending HTTP request with Just:
In both cases, the result of a request
r
can be accessed in ways similar topython-request
:You can find more examples in this playground
Using this library in synchronous mode in a playground is the closest thing to cURL one can get in Swift.
Another option is the Alamofire lib that offers Chainable Request / Response methods.
https://github.com/Alamofire/Alamofire
Making a Request
Response Handling