Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

swiftui api calling github

let params = ["username":"john", "password":"123456"] as Dictionary<String, String>

var request = URLRequest(url: URL(string: "http://localhost:8080/api/1/login")!)
request.httpMethod = "POST"
request.httpBody = try? JSONSerialization.data(withJSONObject: params, options: [])
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

let session = URLSession.shared
let task = session.dataTask(with: request, completionHandler: { data, response, error -> Void in
    print(response!)
    do {
        let json = try JSONSerialization.jsonObject(with: data!) as! Dictionary<String, AnyObject>
        print(json)
    } catch {
        print("error")
    }
})

task.resume()
Comment

swiftui api calling github

var url : String = "http://google.com?test=toto&test2=titi"
var request : NSMutableURLRequest = NSMutableURLRequest()
request.URL = NSURL(string: url)
request.HTTPMethod = "GET"

NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
    var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
    let jsonResult: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary

    if (jsonResult != nil) {
        // process jsonResult
    } else {
       // couldn't load JSON, look at error
    }


})
Comment

swiftui api calling github

For GET Request

 let configuration = NSURLSessionConfiguration .defaultSessionConfiguration()
    let session = NSURLSession(configuration: configuration)


    let urlString = NSString(format: "your URL here")

    print("get wallet balance url string is (urlString)")
    //let url = NSURL(string: urlString as String)
    let request : NSMutableURLRequest = NSMutableURLRequest()
    request.URL = NSURL(string: NSString(format: "%@", urlString) as String)
    request.HTTPMethod = "GET"
    request.timeoutInterval = 30

    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.addValue("application/json", forHTTPHeaderField: "Accept")

    let dataTask = session.dataTaskWithRequest(request) {
        (let data: NSData?, let response: NSURLResponse?, let error: NSError?) -> Void in

        // 1: Check HTTP Response for successful GET request
        guard let httpResponse = response as? NSHTTPURLResponse, receivedData = data
            else {
                print("error: not a valid http response")
                return
        }

        switch (httpResponse.statusCode)
        {
        case 200:

            let response = NSString (data: receivedData, encoding: NSUTF8StringEncoding)
            print("response is (response)")


            do {
                let getResponse = try NSJSONSerialization.JSONObjectWithData(receivedData, options: .AllowFragments)

                EZLoadingActivity .hide()

               // }
            } catch {
                print("error serializing JSON: (error)")
            }

            break
        case 400:

            break
        default:
            print("wallet GET request got response (httpResponse.statusCode)")
        }
    }
    dataTask.resume()
Comment

PREVIOUS NEXT
Code Example
Shell :: linux vga wake up screen 
Shell :: how to install netdata on ubuntu wsl2 
Shell :: overwrite a file name character in linux 
Shell :: bash map lenght 
Shell :: batch malware 
Shell :: sharepoint list password column 
Shell :: remove last field using awk 
Shell :: shell script variables not working 
Shell :: sns3 github 
Shell :: bash multiply float 
Shell :: umount systac 
Shell :: how to mirror your phone to laptop wirelessly 
Shell :: path configuration cmd 
Shell :: bash search multiple string in on line 
Shell :: linux Print the tree view of processes when SSH connection has been established 
Shell :: slurm job specify output directory 
Shell :: base16-shell 
Shell :: install yarn in nginx 
Shell :: E: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/main/binary-arm64/Packages 404 Not Found [IP: 91.189.88.152 80] 
Shell :: get everything before the last / shell 
Shell :: bower install 
Shell :: how to start xamp cpanel in ubuntu 
Shell :: linix and 
Shell :: add line in yaml file using sed 
Shell :: how to convert a multy digit array into a whole number 
Shell :: Não é possível excluir uma partição protegida sem o parâmetro de proteção forçada definido. 
Shell :: cordova admob 
Shell :: install opam on centos 
Shell :: how to clear/delete/remove/erase/wipe/forget shell traps 
Shell :: show all vscode extensions installed in commandline 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =