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.AllowWrit eStreamBuf fering = false;
string postData = fileLine;
// Set 'Method' property of 'HttpWebRequest' class to POST.
myHttpWebRequest.Method = "POST";
ASCIIEncoding encodedData = new ASCIIEncoding();
byte[] byteArray=encodedData.GetB ytes(postD ata);
// Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-ur lencoded".
myHttpWebRequest.ContentTy pe = "application/x-www-form-ur lencoded";
// 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.ContentLe ngth = byteArray.Length;
Stream newStream=myHttpWebRequest .GetReques tStream();
newStream.Write(byteArray, 0,byteArra y.Length);
newStream.Close();
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWeb Request.Ge tResponse( );
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
myHttpWebRequest.AllowWrit
string postData = fileLine;
// Set 'Method' property of 'HttpWebRequest' class to POST.
myHttpWebRequest.Method = "POST";
ASCIIEncoding encodedData = new ASCIIEncoding();
byte[] byteArray=encodedData.GetB
// Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-ur
myHttpWebRequest.ContentTy
// 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.ContentLe
Stream newStream=myHttpWebRequest
newStream.Write(byteArray,
newStream.Close();
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWeb
ASKER
Sorry the error returned is : System.Net.WebException:Co uld not establish trust relationship with remote server.
Cheers
A.
Cheers
A.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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?
ASKER
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
ASKER
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.Certif icatePolic y = 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.AllowWrit eStreamBuf fering = 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.GetB ytes(postD ata);
// Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-ur lencoded".
myHttpWebRequest.ContentTy pe = "application/x-www-form-ur lencoded";
// 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.ContentLe ngth = byteArray.Length;
Stream newStream=myHttpWebRequest .GetReques tStream();
newStream.Write(byteArray, 0,byteArra y.Length);
newStream.Close();
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWeb Request.Ge tResponse( );
myHttpWebResponse.Close();
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.Certif
// Create a new 'HttpWebRequest' object to the mentioned Uri.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest
// Set AllowWriteStreamBuffering to 'false'.
myHttpWebRequest.AllowWrit
myHttpWebRequest.KeepAlive
string postData = fileLine;
Set 'Method' property of 'HttpWebRequest' class to POST.
myHttpWebRequest.Method = "POST";
ASCIIEncoding encodedData = new ASCIIEncoding();
byte[] byteArray=encodedData.GetB
// Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-ur
myHttpWebRequest.ContentTy
// 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.ContentLe
Stream newStream=myHttpWebRequest
newStream.Write(byteArray,
newStream.Close();
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWeb
myHttpWebResponse.Close();
Where does the exception get raised? What's the complite exception info?
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