Hello,
I am getting 401 error while sending messages via HTTP POST. Below are the steps I have followed as per the doc https://github.com/SAP/iot-starterkit
1. Deploy MMS
2. Assign IoT-MMS-user role to my user
3. Under authentication tab, checked the 'user and password' selection (required to get response as success message instead of login page)
4. Created Device type, devices and message types
5. Using the url https://iotmmsd063183trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/[device id] to send message
The application I am using is iOS native application. Below is the code snippet.
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString: @"https://iotmmsd063183trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/[deviceid]"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSString* token = @"[MyToken]";
NSData* bearerToken = [token dataUsingEncoding:NSUTF8StringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Bearer %@", [bearerToken base64EncodedDataWithOptions:4]];
[request setValue:authValue forHTTPHeaderField:@"Authorization: %@"];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Please tell me what I am doing wrong here.
Thanks,
Prathvi