Hi,

I have a .txt file named: myTextFile.txt on my hostingaccount that contains this string: "Hello"

Now my hostingprovider says this:
"Any file that you can access via your domain can be accessed through a Secure Socket Layer (SSL) connection as well."

When I type this manually in the address field, my browser will show the string: "Hello" in the top left corner:
https://myaccount.webhost.com/Folder1/myTextFile.txt

My question now is if it is possible programatically to write this address down in the browser and retreive this string using this Secure Socket Layer (SSL). (https://) ?

I have found out that if I use: http:// like this, I can retreive the string from the file on the server in this MessageBox.

If I exchange http:// to https:// I receive this error:
"The underlying connection was closed: An unexpected error occurred on a send"

I wonder if there is any method to retreive the filecontent using https:// as I want the string to travel encrypted to the C++ application ?

System::Net::WebClient^ Client = gcnew WebClient();
 Stream^ strm = Client->OpenRead("http://myAccount.web.com/Folder1/File1.txt");
 StreamReader^ sr = gcnew StreamReader(strm);    
 String^ line;

 while( sr->Peek() >= 0 )
 {
	 
	 line = line + sr->ReadLine();
 }

 strm->Close();
 MessageBox::Show(line); //This does show the string in the file

I think I am close to a solution by setting the certificates and also UserName and Password to the hostingaccount but still I get the same errormessage:
"The underlying connection was closed: An unexpected error occurred on a send"

RemoteCertificateValidationCallback^ orgCallback = ServicePointManager::ServerCertificateValidationCallback;
 String^ line;
 String^ dummyLine;

 try
 {
	 ServicePointManager::ServerCertificateValidationCallback = gcnew RemoteCertificateValidationCallback(&OnValidateCertificate);   
	 ServicePointManager::Expect100Continue = true;//returning true for all certificates.
																 

	 WebClient^ Client = gcnew WebClient();
	 Client->Credentials = gcnew NetworkCredential("myUserName", "myPassWord");
	 Stream^ strm = Client->OpenRead("https://myAccount.web.com/Folder1/File1.txt");
	 StreamReader^ sr = gcnew StreamReader(strm);    

	 while( sr->Peek() >= 0 )
	 {	
			line = line + sr->ReadLine();
	 }	    
	 sr->Close();
	 strm->Close();
 }
	 catch(Exception^ ex2)
	 {
		 MessageBox::Show(ex2->ToString());
	 }
	 finally
	 {
		 ServicePointManager::ServerCertificateValidationCallback = orgCallback; 
	 }


 MessageBox::Show(line);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.