Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Thank you all.

Let me get wider it more. I set up some properties and send some messages.
Here how I tried to do the client side, but this doesn't work, it retuns different exceptions.
The server side is secured. It is actually a servlet runs on Tomcat.

X509Certificate cert = X509Certificate.CreateFromCertFile(@"servlet.cer");

ServicePointManager.ServerCertificateValidationCallback =
                new System.Net.Security.RemoteCertificateValidationCallback(OnCertificateValidation); // always true

request.ClientCertificates.Add(cert);
request.ContentType = "text/text";

CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(url), "Basic", new NetworkCredential("userID", "password")); 

request.Credentials = myCache;

writer.WriteLine("Why this doesn't work as I wished?");
return;


Hallo Everybody,

Where and when exactly a request does takes place to a particular http/s url?
Here I put sample code:
And this works well.

StreamWriter writer;
StreamReader reader;

string Url = "http://localhost:1212/TestPage";

WebRequest request = WebRequest.create(Url); // ---1--- here or
request.Method = "POST";

writer = new StreamWriter(request.GetRequestStream()); // ---2--- here

WebResponse response = request.GetResponse();

reader = new StreamReader(response.GetResponseStream());

writer.Close();
rsp.Close();
req.GetRequestStream().Close();

return;
Posted
Updated 16-Mar-11 21:12pm
v3
Comments
Yonathan1111 17-Mar-11 9:00am    
Do any of you, didn't see my recent message?
I mean, I tried to get it more wider. Please see it, and say something.

Thanks

In your mark 2 i.e request.GetRequestStream(). The mark 1 just create the WebRequest instance.
 
Share this answer
 
Comments
Venkatesh Mookkan 17-Mar-11 2:52am    
I missed in few seconds. 5!
Espen Harlinn 17-Mar-11 3:43am    
5ed!
Dalek Dave 17-Mar-11 4:59am    
Good Call.
request.GetRequestStream() is the one which is sends to the URL.

One more suggestion: You need to call writer.Close() once you done with writing.
 
Share this answer
 
v2
Comments
Albin Abel 17-Mar-11 3:33am    
No worries. You got an additional point to close the writer/ reader. My 5
Yonathan1111 17-Mar-11 3:34am    
Thanks Venkatesh Mookkan for your suggestion. I actually forgot puting there that line of code.

Thanks
Espen Harlinn 17-Mar-11 3:44am    
5ed!
Dalek Dave 17-Mar-11 5:00am    
Gets my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900