我花了好几天的试验和错误,查看了交换日志,并在互联网上搜索到目前为止无法解决此问题。
我正在iOS应用程序中实现ActiveSync功能,到目前为止已经成功编写了自动发现过程和HTTP OPTIONS请求以获取服务器的功能。我现在正在尝试运行Provision命令但仍然收到400 Bad Request。
以下是我发送给服务器的内容:
URL: https://mobile.[myexchangeserver].com/Microsoft-Server-ActiveSync?Cmd=Provision&User=jack&DeviceID=123412341234&DeviceType=iOS
Authorization = "Basic wekrju283j"; //Base 64 encoded auth, garbage for this posting
"Content-Length" = 104;
"Content-Type" = "application/vnd.ms-sync.wbxml";
"MS-ASProtocolVersion" = "12.1";
"User-Agent" = MyApp;
"X-MS-PolicyKey" = 0;
Body (converted to WBXML before sending):
<?xml version="1.0" encoding="utf-8"?>
<Provision xmlns="Provision:">
<Policies>
<Policy>
<PolicyType>MS-EAS-Provisioning-WBXML</PolicyType>
</Policy>
</Policies>
</Provision>
WBXML: 02 00 25 6A 41 50 72 6F 76 69 73 69 6F 6E 00 50 6F 6C 69 63 69 65 73 00 50 6F 6C 69 63 79 00 50 6F 6C 69 63 79 54 79 70 65 00 2D 2F 2F 41 49 52 53 59 4E 43 2F 2F 44 54 44 20 41 69 72 53 79 6E 63 2F 2F 45 4E 00 44 00 44 0A 44 13 44 1A 03 4D 53 2D 45 41 53 2D 00 83 00 03 69 6E 67 2D 57 42 58 4D 4C 00 01 01 01 01
无论如何,我能找到更多不仅仅是“错误请求”吗?或者有人看到我发送的内容有什么问题吗?服务器支持12.1协议(来自OPTIONS请求)
我一遍又一遍地阅读协议文档,但仍然无法找到我正在做的事情。我知道我可以base64编码参数,但根据protocl docs是可选的。我也知道在14.1中我需要在xml中发送更多信息,因此我使用12.1协议。
非常感谢任何帮助。
答案 0 :(得分:1)
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URI
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:300.0];
NSString *msgLength = [NSString stringWithFormat:@"%d",[requestBodyData length]];
NSLog(@"Request Body Data Length: %@",msgLength);
[request setHTTPMethod:@"POST"];
[request setValue:mAuthStringFinal forHTTPHeaderField:@"Authorization"];
[request setValue:@"iPhone" forHTTPHeaderField:@"DeviceType"];
[request setValue:@"application/vnd.ms-sync.wbxml" forHTTPHeaderField:@"Content-Type"];
[request setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"12.1" forHTTPHeaderField:@"MS-ASProtocolVersion"];
[request setValue:@"*/*" forHTTPHeaderField:@"Accept"];
[request setValue:@"en-us" forHTTPHeaderField:@"Accept-Language"];
[request setValue:nil forHTTPHeaderField:@"X-MS-PolicyKey"];
[request setHTTPBody:requestBodyData];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
/* ensure the connection was created */
if (connection)
{
/* initialize the buffer */
buffer = [NSMutableData data];
/* start the request */
[connection start];
}
else
{
NSLog(@"Connection Failed");
}
我在POST请求中添加了一些标题,我获得了200个状态代码。试试这个! 但是我无法将请求内容作为wbxml发送,而wbxml反过来又提供了一些无意义的字符。
答案 1 :(得分:0)