Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sending HTTPS from a PDA

Posted on 2004-03-20
8
Medium Priority
?
742 Views
Last Modified: 2011-09-20
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();
0
Comment
Question by:astrofunkunator
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:esteban_felipe
ID: 10643145
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
0
 

Author Comment

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

Cheers

A.
0
 
LVL 12

Accepted Solution

by:
esteban_felipe earned 500 total points
ID: 10646920
K, we can start from there...

This problem is ussually associated with the site ssl certificate. Tell me something: if you access the site (with https, of course) using a browser, do you see any popup or message related to the certificate?

There's a common workaround for this issue, but it's not the most secure. It's based in create a new certificatepolicy that accepts all certificate. Here's a class that you can use:
public class TrustThemAll: System.Net.ICertificatePolicy
{
 public TrustThemAll()
 {}

 public bool CheckValidationResult(ServicePoint sp,
  X509Certificate cert,WebRequest req, int problem)
 {
  return true;
 }
}

Then in your code, before declaring the HttpWebRequest you would do:
ServicePointManager.CertificatePolicy = new TrustThemAll();
HttpWebRequest ........ //your code continues here.

Check the site using your browser and implement this workaround. Let me know if you get any good result.

Good luck :)

Esteban Felipe
www.estebanf.com
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:astrofunkunator
ID: 10655233
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
0
 
LVL 12

Expert Comment

by:esteban_felipe
ID: 10655518
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?
0
 

Author Comment

by:astrofunkunator
ID: 10665214

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
0
 

Author Comment

by:astrofunkunator
ID: 10674198
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();
0
 
LVL 12

Expert Comment

by:esteban_felipe
ID: 10674590
Where does the exception get raised? What's the complite exception info?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question