![]() | MessageControllerSendMessage Method |
Namespace: MedTunnelMsg.Controllers
//namespaces to include //using System; //using System.Net; //using System.Web.Script.Serialization; //using System.IO; //using System.Net.Http; //using System.Net.Http.Headers; string authKey = ""; string url; string downloadString; string dataToSend; Result webResult; JavaScriptSerializer serializer = new JavaScriptSerializer(); //if the session has expired then re-login if (!SessionStillActive()) { authKey = Login(); } //var provider = new MultipartMemoryStreamProvider(); //var content = new MultipartFormDataContent(); using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { SendMessage message = new MedTunnelMsg.Models.SendMessage() { ApplicationId = "yourapplicationid", LocationId = "yourlocationid", MedTunnelId = "johndoe@doemedical", //MedTunnelId of the user sending the message MedTunnelPassword = "myPassword", //password of the MedTunnel user sending the message FromMailboxId = 0, //optional - will default to logged in user's mailbox EmailAddress = "jane@janesmedical", Body = "This can be any message text", MessagePassword = "", //only required for messages sent to an e-mail address PatientMedTunnelId = "", //optional - only required for messages sent from a patient account ParentMessageId = 0 //used when replying to a message }; //add the Message object to the request content.Add(new StringContent(serializer.Serialize(message))); //add the file(s) selected in the web form to the request foreach (UploadedFile postedFile in FileUpload1.UploadedFiles) { //read the file contents into a byte array BinaryReader br = new BinaryReader(postedFile.InputStream); var fileContent = new ByteArrayContent(br.ReadBytes(Convert.ToInt32(postedFile.ContentLength))); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = postedFile.FileName }; content.Add(fileContent); } url = "https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage"; client.DefaultRequestHeaders.Add("Authorization", authKey); var sendResult = client.PostAsync(url, content).Result; webResult = serializer.Deserialize<Result>(sendResult.Content.ReadAsStringAsync().Result); if (webResult.ReturnCode != 1) { throw new Exception("SendFailed"); } } }
Message text only ----------------- curl https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" -F "To=recipientsMedTunnelId" -F "Body=Test of SendMessage" Message with a file attachment ------------------------------ curl https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" -F "To=recipientsMedTunnelId" -F "Body=Test of SendMessage" -F "file1=@C:\temp\Desert.jpg"