Reputation: 31
I got 505 error(Http version not supported) in following api for active sync.
let userName = "userName.onmicrosoft.com"
let safeUserName = userName.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let deviceid = UIDevice.current.identifierForVendor!.uuidString
let authString = "userName.onmicrosoft.com:12345"
let data = (authString).data(using: String.Encoding.utf8)
let base64 = "Basic \(data!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0)))"
let urlToRequest = "https://outlook.office365.com:443/Microsoft-Server-ActiveSync"
let url4 = URL(string: urlToRequest)!
let session4 = URLSession.shared
let request = NSMutableURLRequest(url: url4)
request.httpMethod = "POST"
request.addValue(base64, forHTTPHeaderField: "Authorization")
request.addValue("keep-alive", forHTTPHeaderField: "Connection")
request.addValue("iPhone/0.3", forHTTPHeaderField: "User-Agent")
let params = ["Cmd": "OPTIONS", "User": "\(safeUserName!)", "DeviceId": "\(deviceid)","DeviceType":"iPhone"] as [String : Any]
request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: [])
let task = session4.dataTask(with: request as URLRequest) { (data, response, error) in
if (error != nil){
print("response---->",response)
}
}
task.resume()
Geeting error response like this
▿ Optional<NSURLResponse>
- some : <NSHTTPURLResponse: 0x281ae28a0> { URL: https://outlook.office365.com:443/Microsoft-Server-ActiveSync } { Status Code: 505, Headers {
"Cache-Control" = (
private
);
"Content-Length" = (
71
);
"Content-Type" = (
"text/html"
);
Date = (
"Mon, 17 Jun 2019 05:57:50 GMT"
);
Server = (
"Microsoft-IIS/10.0"
);
"X-AspNet-Version" = (
"4.0.30319"
);
"X-BEServer" = (
MAXPR01MB4096
);
"X-BackEndHttpStatus" = (
505,
505
);
"X-CalculatedBETarget" = (
"MAXPR01MB4096.INDPRD01.PROD.OUTLOOK.COM"
);
"X-CalculatedFETarget" = (
"MA1PR0101CU003.internal.outlook.com"
);
"X-DiagInfo" = (
MAXPR01MB4096
);
"X-FEProxyInfo" = (
"MA1PR0101CA0054.INDPRD01.PROD.OUTLOOK.COM"
);
"X-FEServer" = (
MA1PR0101CA0054,
PN1PR0101CA0057
);
"X-MS-BackOffDuration" = (
"L/-470"
);
"X-Powered-By" = (
"ASP.NET"
);
"X-RUM-Validated" = (
1
);
"request-id" = (
"a85221f0-b594-4047-a366-ae164e721982"
);
} }
Need to expect HTTP/1.1 200 OK reponse like that
HTTP/1.1 200 OK Cache-Control: private Allow: OPTIONS,POST Server: Microsoft-IIS/7.0 MS-Server-ActiveSync: 14.00.0536.000 MS-ASProtocolVersions: 2.0,2.1,2.5,12.0,12.1,14.0 MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy, CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate, FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search, Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert Public: OPTIONS,POST X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET Date: Thu, 12 Mar 2009 20:03:29 GMT Content-Length: 0
Upvotes: 1
Views: 1545