-1

Please correct this code

@IBAction func registeruser(sender: AnyObject) {
    let usertext = useremail.text;

    let myURL = NSURL(string: "http://advaluead.com/vishwa/index.php");
    let request = NSMutableURLRequest(URL:myURL!);
    request.HTTPMethod = "POST";

    let poststring = "email=\(usertext)";
    request.HTTPBody = poststring.dataUsingEncoding(NSUTF8StringEncoding);

}

My server is not getting any request from the App.

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
Vishwa Raj
  • 57
  • 1
  • 9

2 Answers2

1
let myURL = NSURL(string: "http://advaluead.com/vishwa/index.php");
            let postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!
            let postLength:NSString = String( postData.length )
            let request:NSMutableURLRequest = NSMutableURLRequest(URL: url!)
            request.timeoutInterval = 120
            request.HTTPMethod = "POST"
            request.HTTPBody = postData
            request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
            request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
            request.setValue("application/json", forHTTPHeaderField: "Accept")

pls. check once.

Rushabh Shah
  • 396
  • 3
  • 19
0

You need to disable ATS (App Transport Security) or authorize the domain because you are not using https.

To "brutally" disable all http calls (not the best option), add this to your Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

The recommended way to go is to keep ATS and configure domain exceptions this way:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

More info here

H4Hugo
  • 2,570
  • 3
  • 16
  • 32
  • 1
    Be aware that apple will require all server communication to use TLS in the near future and this option will not work any more. – rckoenes Jul 13 '16 at 12:10