Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

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


11 Comments