cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

Error: The remote certificate is invalid according to the validation proced

57
Views
0
Helpful
0
Comments
This document was generated from CDN thread

Created by: Manas Varma on 23-03-2011 08:10:24 AM
Hi All,
 
I am trying to add a new user using CUPI. Here is my code below. Can you please suggest what changes I need to perform for it to work. I am using c#
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


   string ExtQuery = "";
        ExtQuery = "<?xml version=1.0 encoding=UTF-8 standalone=yes?>";
        ExtQuery += "<User>";
        ExtQuery += "<Alias>varmam</Alias>";
        ExtQuery += "<DtmfAccessId>25311</DtmfAccessId>";
        ExtQuery += "<FirstName>Manas</FirstName>";
        ExtQuery += "<LastName>Varma</LastName>";
        ExtQuery += "<DisplayName>Manas Varma</DisplayName>";
        //ExtQuery += "<PhoneSystemURI>/vmrest/phonesystems/3486d6b3-1b98-4538-98a7-ea89a4758d74</PhoneSystemURI> ";
        ExtQuery += "<CosObjectId>7d241b5a-a278-4df1-b081-475fafc07eee</CosObjectId>";
        ExtQuery += "<SkipPasswordForKnownDevice>true</SkipPasswordForKnownDevice>";
        ExtQuery += "<IsSetForVmEnrollment>false</IsSetForVmEnrollment>";
        ExtQuery += "<IsVmEnrolled>false</IsVmEnrolled>";
        ExtQuery += "<RouteNDRToSender>false</RouteNDRToSender>";
        ExtQuery += "</User>";
 
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://10.197.210.15/vmrest/users");
        req.Accept = "application/application/xml";
        req.ContentType = "application/application/xml";
        req.Method = "POST";
        req.KeepAlive = true;
        byte[] authorizationHeaderBytes = System.Text.Encoding.UTF8.GetBytes("user" + ":" + "password");
        string authHeader = "Basic " + Convert.ToBase64String(authorizationHeaderBytes);
        req.Headers.Add("Authorization", authHeader);
        //  req.Credentials = new System.Net.NetworkCredential("user", "password");
        Stream s = req.GetRequestStream();
        s.Write(System.Text.Encoding.ASCII.GetBytes(ExtQuery), 0, ExtQuery.Length);
        s.Close();
        WebResponse resp = req.GetResponse();
        StreamReader sr = new StreamReader(resp.GetResponseStream());
        string XMLResult = sr.ReadToEnd();
        Response.Write(XMLResult);
 
Please suggest.
<font size="2">
 
</font>
 

Subject: RE: Error: The remote certificate is invalid according to the validation pr
Replied by: Mayank Sharma on 23-03-2011 08:18:25 AM
Create a new Class like this:

public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
    public TrustAllCertificatePolicy()
    { }

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

Then instantiate it just before you do your CUPI work.
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

Basically, the error says that the cert is invalid, you are just ignoring that error like this.

Subject: RE: Error: The remote certificate is invalid according to the validation pr
Replied by: Mayank Sharma on 23-03-2011 08:19:28 AM
You need to add "using System.Security.Cryptography.X509Certificates;" namespace too.

Subject: RE: Error: The remote certificate is invalid according to the validation pr
Replied by: Manas Varma on 23-03-2011 10:29:09 AM
You need to add "using System.Security.Cryptography.X509Certificates;" namespace too.


Thanks Mayank. It workded , but I am getting BAD Request (400) error after that. Can you please suggest , if there is something wrong with the query that I am passing for adding users.
CreatePlease to create content
Content for Community-Ad
FusionCharts will render here