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
In Swift 4.1 and Xcode 9.4.1.
JSON POST approach example
If you have interest to use this function in SharedClass
And finally call this function like this....
I have done HTTP Request Both methods GET & POST with JSON Parsing this way:
on viewDidLoad():
Done
An example for a sample "GET" request is given below.
//Here is an example that worked for me
//Swift function that post a request to a server with key values
PHP Code to get the key values
$empID = $_POST['id'];
$inOut = $_POST['inout'];
$comment = $_POST['comment'];
Here's a very simple Swift 4 example in a playground:
I am using this guy's wrapper with good results so far https://github.com/daltoniam/swiftHTTP. No big leaky abstractions so far
Example