2016-08-03 3 views
0

Ich bekomme INPUT_VALIDATION_ERROR beim Einloggen in Betfair API. Ich folge den Dokumenten, aber es war nutzlos mit diesem speziellen Fehlercode.INPUT_VALIDATION_ERROR in BetFair Anmeldung API/iOS

Ich würde mich freuen, wenn jemand mich in die richtige Richtung führen könnte.

Hier ist mein SWIFT-Code

let request = NSMutableURLRequest(URL: NSURL(string: "https://identitysso.betfair.com/api/login")!) 
     request.HTTPMethod = "POST" 


       request.setValue("application/json", forHTTPHeaderField: "Accept") 
     request.setValue("MY_APP_KEY", forHTTPHeaderField: "X-Application") 


     let postString = "username=MY_USER_NAME&password=MY_PASSWORD" 
     request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) 

     let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in 
      guard error == nil && data != nil else {               // check for fundamental networking error 
       print("error=\(error)") 
       return 
      } 

      if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 {   // check for http errors 
       print("statusCode should be 200, but is \(httpStatus.statusCode)") 
       print("response = \(response)") 
      } 

      let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding) 
      print("responseString = \(responseString)") 
     } 
     task.resume() 

Antwort

2

Ich glaube, Sie Header in http für Content-Type als

application/x-www-form-urlencoded 

Drei Parameter in HTTP-Header festlegen müssen:

httpRequest.setHeader("Accept", "application/json"); 
    httpRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); 
    httpRequest.setHeader("X-Application", <apiKey>); 
+0

Es funktioniert für mich! – Klevison

+0

Cool, es hat für dich funktioniert – sendon1982