Hello all,
I am trying to send some data using data stream to DigiCloud. I managed to write this function:
try
{
byte[] data = UTF8Encoding.UTF8.GetBytes("{\r\n\" \"stream_id\": \"G120M_test\",\r\n \"stream_type\": \"STRING\",\r\n \"value\": \"" + DateTime.Now.ToString() + "\"\r\n}\r\n");
Uri url = new Uri("https://devicecloud.digi.com/ws/v1/streams/history");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
Debug.Print("Adres URL: " + url.OriginalString);
request.Method = "POST";
String username = "username";
String password = "password";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
request.Headers.Add("Authorization", "Basic " + encoded);
request.ContentLength = data.Length;
request.ContentType = "application/json";
request.Accept = "application/json";
Debug.Print("HttpWebRequest: " + request.GetRequestStream().Length);
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
request.Dispose();
Debug.Print(((HttpWebResponse)response).StatusDescription);
Stream respData = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Debug.Print(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
}
catch (Exception e)
{
byte[] buffer = Encoding.UTF8.GetBytes("Error:" + e);
UART.Write(buffer, 0, buffer.Length);
Debug.Print("Error:" + e);
}
I had searched over the Internet and found solution to update SSL feed. However, that didnât work for me. Iâm still getting exceptions:
[quote] #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureRead [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Read [IP: 0040] ####
#### System.Net.InputNetworkStreamWrapper::RefillInternalBuffer [IP: 0038] ####
#### System.Net.InputNetworkStreamWrapper::Read_HTTP_Line [IP: 004b] ####
#### System.Net.HttpWebRequest::ParseHTTPResponse [IP: 002e] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 0035] ####
#### Drzemlik_brama_G120E.DeviceCloud::.ctor [IP: 00c8] ####
#### Drzemlik_brama_G120E.Program::Main [IP: 0061] ####
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.Security.dll
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### Drzemlik_brama_G120E.DeviceCloud::.ctor [IP: 00c8] ####
#### Drzemlik_brama_G120E.Program::Main [IP: 0061] ####
A first chance exception of type âSystem.Net.WebExceptionâ occurred in System.Http.dll
Error:System.Net.WebException[/quote]
Did somebody have similiar problem and please could help me?
Regards