Link to home
Start Free TrialLog in
Avatar of astrofunkunator
astrofunkunator

asked on

Sending HTTPS from a PDA

Hi there,

I am using the following code to send via HTTP but I would rather send via HTTPS, if i change the http to https it crashes. Any healp would be wonderful..

// Create a new 'HttpWebRequest' object to the mentioned Uri.                
                              HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://xxx.xxx.xxx.xx/cgi-bin/pda/inbound");                        
                                                            myHttpWebRequest.AllowWriteStreamBuffering = false;
                        
                              string postData = fileLine;
                              
                              // Set 'Method' property of 'HttpWebRequest' class to POST.
                              myHttpWebRequest.Method = "POST";
                              
                              ASCIIEncoding encodedData = new ASCIIEncoding();
                              
                              byte[]  byteArray=encodedData.GetBytes(postData);
                              
                              // Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-urlencoded".
                              myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                              
                              // If the AllowWriteStreamBuffering property of HttpWebRequest is set to false,the contentlength has to be set to length of data to be posted else Exception(411) is raised.
                              myHttpWebRequest.ContentLength = byteArray.Length;
                              
                              Stream newStream=myHttpWebRequest.GetRequestStream();
                              
                              newStream.Write(byteArray,0,byteArray.Length);
                              
                              newStream.Close();
                              
                              // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
                              HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Avatar of esteban_felipe
esteban_felipe

Hi astrofunkunator,

what do you mean with "it crashes"? what exception is it throwing?. That information will be useful to find out a solution

Esteban Felipe
www.estebanf.com
Avatar of astrofunkunator

ASKER

Sorry the error returned is : System.Net.WebException:Could not establish trust relationship with remote server.

Cheers

A.
ASKER CERTIFIED SOLUTION
Avatar of esteban_felipe
esteban_felipe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the suggestion. I implemented your change but unfortunately I am still receiving the same error. System.net.WebException : The remote name could not be resolved.

When i try and access the cgi through a browser it works fine, no cert messages, just the standard "No document received."

Regards
Marcus
But the exception changed. It used to be: "Could not establish trust relationship with remote server" and now it's  "The remote name could not be resolved". Do you have access from the pda to the site? and what do you mean with "the standard no document recieved"? is the target page expecting something?

Sorry my mistake, changed to the web address rather then the IP and it works a treat. Thank you very very much for you assistance..

Regards

Marcus
Still not working!!

It works once then i get the  "A blocking operation is currently excuting"!! I close the response and the stream??

What is there left to close?

// Ensure the trust relation ship for
ServicePointManager.CertificatePolicy = new TrustThemAll();


// Create a new 'HttpWebRequest' object to the mentioned Uri.                
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create   ("https://203.174.144.37/cgi-bin/pda/inbound");                        

// Set AllowWriteStreamBuffering to 'false'.
myHttpWebRequest.AllowWriteStreamBuffering = false;

myHttpWebRequest.KeepAlive = false;
                        
string postData = fileLine;
                              
Set 'Method' property of 'HttpWebRequest' class to POST.
myHttpWebRequest.Method = "POST";

ASCIIEncoding encodedData = new ASCIIEncoding();
                              
byte[]  byteArray=encodedData.GetBytes(postData);

// Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-urlencoded".

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// If the AllowWriteStreamBuffering property of HttpWebRequest is set to false,the contentlength has to be set to length of data to be posted else Exception(411) is raised.

myHttpWebRequest.ContentLength = byteArray.Length;

Stream newStream=myHttpWebRequest.GetRequestStream();

newStream.Write(byteArray,0,byteArray.Length);

newStream.Close();

// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

myHttpWebResponse.Close();
Where does the exception get raised? What's the complite exception info?