B
B Martin
Hello,
I am having some trouble posting xml to a site that is set up to accept
client certificates (as well as requires certificates). My program
will just hang forever when I try to add the xml to the request stream
(see code below) of the HttpWebRequest object. It hangs regardless of
whether I have added the certificate to the HttpWebRequest object, so I
do not believe it is my certificate causing this. I have the web site
I'm posting to set up to accept client certificates, require SSL, and
to authenticate by windows auth (all of which I need to do).
When I change either the authentication mode to anonymous or the client
certificates to ignore, the code below works fine. If I do not post
any data but to a GET instead, then the code will connect just fine
(and return the HTML). I've tried everything I could think of and it
will just not work.
There is definitely a deadlock issue here -- although I cannot
understand why the Write method is affected. Does anyone see anything
that I'm doing wrong here or has run into this before?
Thanks.
BM
=======================================================
string xml = "<ROOT>test</ROOT>";
string results = string.Empty;
Uri uri = new Uri("https://localhost/MyReceiver.aspx");
//create the request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "text/xml";
request.Method = "POST";
request.KeepAlive = true;
request.Credentials = CredentialCache.DefaultCredentials;
//Set the certificate - load from file
request.ClientCertificates.Add(GetCertificate());
byte[] data = Encoding.ASCII.GetBytes(xml);
request.ContentLength = data.Length;
Stream dataStream = null;
try{
dataStream = request.GetRequestStream();
// Write the data to be posted.
dataStream.Write(data, 0, data.Length); //HANGS here
}
finally{
if (dataStream != null){
dataStream.Close();
dataStream = null;
}
}
HttpWebResponse response = null;
StreamReader reader = null;
try{
//Get the response
response = (HttpWebResponse)request.GetResponse();
reader = new StreamReader(response.GetResponseStream());
results = reader.ReadToEnd();
}
finally{
if (reader != null){
reader.Close();
reader = null;
}
if (response != null){
response.Close();
response = null;
}
}
I am having some trouble posting xml to a site that is set up to accept
client certificates (as well as requires certificates). My program
will just hang forever when I try to add the xml to the request stream
(see code below) of the HttpWebRequest object. It hangs regardless of
whether I have added the certificate to the HttpWebRequest object, so I
do not believe it is my certificate causing this. I have the web site
I'm posting to set up to accept client certificates, require SSL, and
to authenticate by windows auth (all of which I need to do).
When I change either the authentication mode to anonymous or the client
certificates to ignore, the code below works fine. If I do not post
any data but to a GET instead, then the code will connect just fine
(and return the HTML). I've tried everything I could think of and it
will just not work.
There is definitely a deadlock issue here -- although I cannot
understand why the Write method is affected. Does anyone see anything
that I'm doing wrong here or has run into this before?
Thanks.
BM
=======================================================
string xml = "<ROOT>test</ROOT>";
string results = string.Empty;
Uri uri = new Uri("https://localhost/MyReceiver.aspx");
//create the request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "text/xml";
request.Method = "POST";
request.KeepAlive = true;
request.Credentials = CredentialCache.DefaultCredentials;
//Set the certificate - load from file
request.ClientCertificates.Add(GetCertificate());
byte[] data = Encoding.ASCII.GetBytes(xml);
request.ContentLength = data.Length;
Stream dataStream = null;
try{
dataStream = request.GetRequestStream();
// Write the data to be posted.
dataStream.Write(data, 0, data.Length); //HANGS here
}
finally{
if (dataStream != null){
dataStream.Close();
dataStream = null;
}
}
HttpWebResponse response = null;
StreamReader reader = null;
try{
//Get the response
response = (HttpWebResponse)request.GetResponse();
reader = new StreamReader(response.GetResponseStream());
results = reader.ReadToEnd();
}
finally{
if (reader != null){
reader.Close();
reader = null;
}
if (response != null){
response.Close();
response = null;
}
}