1

扯掉我的头发。我们有一个 p12 文件,它不能导出到 .pfx,所以 stackoverflow 上的解决方案没有帮助。

使用 SOAPUI,我得到了响应,但是从作为控制台应用程序编写的 C# (2014) 客户端,我只收到 405 错误。

代码如下:

        string host = "https://dev-cust-ws.m2xxx.com:8443/xyz/supplier/ws";
        string certName = @"C:\\Users\\Neal.Rogers\\Desktop\\fmcgx201802.p12";
        string password = @"fmGCG@fGnnnn";

        X509Certificate2Collection certificates = new X509Certificate2Collection();
        certificates.Import(certName, password, X509KeyStorageFlags.UserKeySet | X509KeyStorageFlags.PersistKeySet);

        ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host);
        req.AllowAutoRedirect = true;
        req.ClientCertificates = certificates;
        req.ContentType = "application/x-www-form-urlencoded";
        req.Method = "POST";
        req.ContentLength = (long)strEnvelope.Length;

        Stream postStream = req.GetRequestStream();
        postStream.Write(postDataBytes, 0, (int)postDataBytes.Length);
        postStream.Flush();
        postStream.Close();
        WebResponse resp = req.GetResponse();

也尝试了以下

 string soapUrl = "https://dev-cust-ws.m2xxxx.com:8443/xyz/supplier/ws";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(soapUrl);
            request.ContentType = "application/x-www-form-urlencoded";

            var store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            var cert = store.Certificates.Find(X509FindType.FindByThumbprint, "D0C126412A77DEA313A926DBC34BFC1EDDEDFD58", false)[0];
            request.ClientCertificates.Add(cert);
            request.Method = "POST";
            request.Timeout = 60000;
            request.ContentLength = (long)strEnvelope.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(postDataBytes, 0, (int)postDataBytes.Length);
            requestStream.Close();
            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
            strReturn = responseReader.ReadToEnd();
            resp.Close();

提前致谢

4

0 回答 0