For the basic authentication, use the credentials of the API user. To create an API user, refer to Creating an API user or Creating an API user via API.
We recommend you to use preemptive authentication. That way, the basic authentication request is sent before the server returns an unauthorized response. Also refer to the Apache documentation.
Sending data
This C# code example shows you how to send data to the Data Recorder Service of the Bosch IoT Insights backend using C# code.
public string uploadFileToiot-insights(string ProjectName,string Username, string Password, string FilePath, string ProxyUrl,int ProxyPort, string ProxyUserName, string ProxyPassword)// If you are inside your company network, proxy authentication may be required. Otherwise, you can remove this from the example. This is an example for a Bosch internal proxy.{ // Switch all follwing webrequests to use TLS 1.2, other protocols (SSL3/TLS1.0/TLS1.1) are not secure anymore ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Create A Web request to iot-insights HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://www.bosch-iot-insights.com/data-recorder-service/v2/" + ProjectName); webRequest.Timeout = 30000; webRequest.Method = "POST"; // Define your content type e.g. xml, json, ... webRequest.ContentType = "application/xml"; // Set the iot-insights password webRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String (System.Text.Encoding.Default.GetBytes(""+ Username + ":" + Password))); // If a proxy url is set use it if ( ProxyUrl != null ) { // set user name and password as credentials for the proxy WebProxy proxyHTTP = new WebProxy(ProxyUrl, ProxyPort); ICredentials proxyCredentials = new NetworkCredential(ProxyUserName, ProxyPassword); proxyHTTP.Credentials = proxyCredentials; webRequest.Proxy = proxyHTTP; } // Read the content of the given file and convert file data to byte array StringBuilder fileContent = new StringBuilder(); StreamReader fileReader = new StreamReader(FilePath); String line = ""; while ((line = fileReader.ReadLine()) != null) { fileContent.AppendLine(line); } fileReader.Close(); byte[] fileContentBytes = Encoding.UTF8.GetBytes(fileContent.ToString()); // Attach the content to the output stream webRequest.ContentLength = fileContentBytes.Length; webRequest.GetRequestStream().Write(fileContentBytes, 0, fileContentBytes.Length); webRequest.GetRequestStream().Flush(); webRequest.GetRequestStream().Close(); // finally transmit this Web Request to iot-insights HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); // a Successful answer will be OK returned from the Website Console.WriteLine( "WebResponse Contains " + webResponse.StatusDescription ); if (webResponse.StatusCode == System.Net.HttpStatusCode.OK) { return true; } else { return false; }}