EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Sample C# application for TElHTTPSClient

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#35125
Posted: 11/27/2015 12:26:04
by Peter Johnson (Basic support level)
Joined: 11/26/2015
Posts: 3

I searched for forum on "TElHTTPSClient post sample" and read all posting and found none can help me to translate the following code to TEIHTTPSClient. Any help to fill in the missing pieces would be appreciated:

Code
    System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(webServiceUrl);   
    httpWebRequest.Method = "POST";    
    httpWebRequest.ContentType = "text/xml";
    ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls;    
    httpWebRequest.Credentials = new NetworkCredential("userA","pwd");    
    byte[] postData = System.Text.Encoding.UTF8.GetBytes("c:\\FileToUpload.txt");
    httpWebRequest.ContentLength = postData.Length;
    Stream newStream = httpWebRequest.GetRequestStream();
    newStream.Write(postData, 0, postData.Length);
    newStream.Close();    
    System.Net.WebResponse myWebResponse = httpWebRequest.GetResponse();


----------- based on the HTTP post sample I got the following ----------
Code
    private SBHTTPSClient.TElHTTPSClient HTTPSClient;
    //How to set content type?
    HTTPSClient.SSLEnabled = true;
    HTTPSClient.SSLOptions = (byte)SBSSLConstants.Unit.sbTLS1;
    HTTPSClient.RequestParameters.Username = "userA";
    HTTPSClient.RequestParameters.Password = "pwd";
    HTTPSClient.Post(edURL.Text, System.Text.Encoding.UTF8.GetBytes("c:\\FileToUpload.txt"));
    //How to get response?
#35126
Posted: 11/27/2015 12:30:37
by Eugene Mayevski (EldoS Corp.)

Thank you for contacting us.

Content type is set in HTTPSClient.RequestParameters.ContentType property.

Response is written to the stream which you assign to TElHTTPSClient.OutputStream property.

On a side note it would help a lot if you used CODE button located above the text entry box (alternatively you can write [ CODE ] and [ /CODE ] tags by hand) to mark the beginning and the end of the code blocks in your messages. This would enable syntax highlighting and line numbering on the code and make it easier for analysis.


Sincerely yours
Eugene Mayevski
#35127
Posted: 11/27/2015 15:16:01
by Peter Johnson (Basic support level)
Joined: 11/26/2015
Posts: 3

Thanks for the quick response. It is difficult for new developers as there is small number of samples. However, your support service turn around time is impressive.

So here is the resulting code. Let me know if I miss anything.
Code
private SBHTTPSClient.TElHTTPSClient HTTPSClient;
    
    HTTPSClient.SSLEnabled = true;
    HTTPSClient.SSLOptions = (byte)SBSSLConstants.Unit.sbTLS1;
    HTTPSClient.RequestParameters.Username = "userA";
    HTTPSClient.RequestParameters.Password = "pwd";
    HTTPSClient.RequestParameters.ContentType = ""text/xml";

   // additional lines for assigning stream to OutputStream
   MemoryStream ms = new MemoryStream();
   HTTPSClient.OutputStream = ms;

    HTTPSClient.Post(edURL.Text, System.Text.Encoding.UTF8.GetBytes("c:\\FileToUpload.txt"));

   // additional lines to read the response from OutputStream
   ms.Position = 0;
   StreamReader sr = new StreamReader(ms);
   string response = sr.ReadToEnd();
#35128
Posted: 11/27/2015 15:35:26
by Eugene Mayevski (EldoS Corp.)

The code looks fine. Are you having problems with it?

About the CODE tag - the space between the brackets and the keyword is not needed. It is present in my message because otherwise the forum engine will treat my text as tags. It's easier to use the buttons above the message box - they will put correct tags.


Sincerely yours
Eugene Mayevski
#35129
Posted: 11/27/2015 17:59:28
by Peter Johnson (Basic support level)
Joined: 11/26/2015
Posts: 3

No problem yet as just wanting to get the skeleton going first. Need your code review to ensure I got the basic working.

Take some experimenting to go to next level.

Thanks a lot.

Peter
#35133
Posted: 11/30/2015 03:54:16
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Quote
HTTPSClient.SSLOptions = (byte)SBSSLConstants.Unit.sbTLS1;

This line is not correct and should be replaced with

Code
HTTPSClient.Versions = SBSSLConstants.Unit.sbTLS1;


if you want to enable TLS1 only. However I recommend you to remove this option and leave TLS settings with default values until you realy need to tune them up.
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 2449 times

Number of guests: 2, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!