快速获得HTTP OPTIONS命令请求和活动同步响应中的505错误

时间:2019-06-17 09:01:14

标签: ios swift email activesync

以下用于主动同步的api中出现505错误(不支持Http版本)。

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错误响应

▿ 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"
);
} }

需要这样的HTTP / 1.1 200 OK响应

HTTP / 1.1 200 OK缓存控制:私有允许:OPTIONS,POST服务器: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 -ASProtocol命令:同步,发送邮件,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,搜索,Settings,Ping,ItemOperations,选项,POST X-AspNet版本:2.0.50727 X-Powered-由:ASP.NET日期:Thu,2009年3月12日20:03:29 GMT内容长度:0

0 个答案:

没有答案