Search code examples
iosswiftpostnsurlconnection

How to POST integer request to server in swift ios?


    let theRequest = NSMutableURLRequest(URL: url!)
    theRequest.HTTPMethod = "POST"

    let parameters = ["otp":firstDigit.text!,"otp":secondDigit.text!,"otp":thirdDigit.text!,"otp":fourthDigit.text!] as Dictionary<String,String>

How to add parameters to pass numbers in to the server side. There is only one field in the server side and I have to pass 4 integers using four different text fields. How can I pass it? Basically I am passing an OTP(One time password with four digits)


Solution

  • First make the OTP variable like this:-

     var otpText:String= firstDigit.text + secondDigit.text +thirdDigit.text+fourthDigit.text
    

    then form the parameter:-

    let parameters : NSDictionary =["otp":otpText]