1

I have spent days of trial and error, looked through exchange logs, and searched all over the internet and so far am unable to resolve this issue.

I am implementing ActiveSync capabilities within my iOS app and so far have successfully coded the autodiscover process and the HTTP OPTIONS request to get the server's capabilities. I am now trying to run the Provision command but keep getting 400 Bad Request.

Here is what I am sending to the server:

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

Is there anyway I can find out more than just "Bad Request"? Or does anyone see anything wrong with what I'm sending in? The server supports the 12.1 protocol (from the OPTIONS request)

I've read through the protocol documentation over and over and still can't find anything wrong with what I'm doing. I know I can base64 encode the paramaters, but according the protocl docs that is optional. I also know that in 14.1 I need to send more information in the xml, hence why I'm using the 12.1 protocol.

Any help is greatly appreciated.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jack Freeman
  • 1,414
  • 11
  • 18
  • are you behind a firewall? – Dan Jul 11 '13 at 04:05
  • No and I can successfully connect and authenticate with autodiscover and OPTIONS – Jack Freeman Jul 11 '13 at 06:12
  • I have an Exchange Server configured and I'm trying just to test the authentication from an iOS app. From a view the user shall enter email, username and password and I want to make the request just to authenticate the user. Can you provide me some guidance how to to that? – dorin Aug 29 '14 at 06:55

3 Answers3

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

I have added some more headers in the POST request and I am getting 200 status code. Try this! But I am not being able to send the request content as wbxml which in turn is providing some meaningless characters in response.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
0

The namespace on your Provision command looks wrong. It should be "Provision" and not "Provision:".

I'm assuming you got the XML from some of Microsoft's examples in the [MS-ASPROV].pdf document. In many cases, I have found Microsoft's XML samples to contain typos.

Sorry this response did not come much sooner. Hopefully, it may help someone else in the future.

Nate
  • 1
0

For a possible answer to this question, I spent the better half of the day tracking down the vague "bad request" reasoning for my case, and it was the Device ID. The device ID max length seems to be 16 characters—for at least Exchange's ActiveSync 14.1 implementation—despite the MS-ASHTTP manual saying 32 chars.

enter image description here

Unrelated: regarding the trailing colon in namespace names, I've seen that version of namespaces in a lot of examples. libwbxml also seems to expect it or generate it in some places. It's very quirky.

mukunda
  • 2,908
  • 15
  • 21