cancel
Showing results for 
Search instead for 
Did you mean: 

Preflight request doesnt pass access control check when sending POST to IoTMMS via WS

0 Kudos

I have created an HTML5 app that i am running in HCP which shows sensor data coming off my Raspberry PI which works fine. However i would like to enable bi-directional communication and also be able to send messages to it via the Websockets Push functionality. I have defined my ajax request with the following parameters:

type: 'POST'

headers: "Authorization" : "Bearer b6d385552c9c49090ad65c48e896dc4"

url:https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc-47b0-b09d-00f318da5d1d

data: ("method":"ws", "sender":"Sensor Monitor Application", "messageType":"243dbaf4dcb840dfafbe", "messages":[ { "photo_request": "false", "led_display": "test test"]}

Where the photo_request boolean is for the pi camera to capture an image and the led_display string to display the message on the LED display.

However when i trigger the call i get the following error. I can send the POST via POSTMAN but not through Chrome as i test my app through WebIDE:

Failed to load resource: the server responded with a status of 401 (Unauthorized) https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc...

XMLHttpRequest cannot load https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc.... Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting0272800-d2b412a60.dispatcher.us2.hana.ondemand.com' is therefore not allowed access. The response had HTTP status code 401.

I have configured Destinations as well which i have read are required to avoid this CORS issue but in my case it does not appear to have any effect. See Destintions below:

Name=IoT_MMS_API Description=IoT MMS API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=https\://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms User=XXXXXX

Name=IOT_RDMS_API Description=IOT_RDMS_API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=

https\://iotrdmsiotservices-d2b412a60.us2.hana.ondemand.com/com.sap.iotservices.dms

User=XXXX

Does anyone know what's missing in order to push messages to a device from a web interface? I think i've followed the documentation to a T but still appear to be missing something. Thanks in advance for your help!

View Entire Topic
anton_levin
Advisor
Advisor
0 Kudos

I'd recommend to have a look on a StarterKit example [1], where messages are pushed from web application to the device via HTTP, WS and MQTT.

[1] https://github.com/SAP/iot-starterkit/tree/master/src/apps/java/consumption

0 Kudos

Is there an updated link to this? I get a 404 when attempting to access that page