通过HTTPS发布JSON

在过去,我已经通过HTTP成功调用了JSON webservice但是,现在我必须通过HTTPS创建JSON POST。

我曾尝试使用适用于HTTP的代码,并简单地将被调用的网址更改为https,但不起作用。

这是我正在使用的代码...

WebRequest wrGETURL;
wrGETURL = WebRequest.Create("https://apitest.example.com/geo/coverage/v1/?appId=2644571&appKey=836621d715b6ce4db5f007d8fa2214f");
wrGETURL.Method = "POST";
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
string responseFromServer = objReader.ReadToEnd();

并且我在小提琴手中看到的错误消息是:

fiddler.network.https>无法保护apitest.example.com的现有连接。 对SSPI的调用失败,请参阅内部异常。 InnerException:System.ComponentModel.Win32Exception(0x80004005):客户端和服务器无法通信,因为它们不具有通用算法

任何人都可以帮我解决我需要通过HTTPS拨打电话吗?


你需要认证还是服务器证书的回调? 这在大多数情况下适用于我:

        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://someurl/");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "POST";

        // Create NetworkCredential Object 
        NetworkCredential admin_auth = new NetworkCredential("username", "password");

        // Set your HTTP credentials in your request header
        httpWebRequest.Credentials = admin_auth;

        // callback for handling server certificates
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{"name":"TEST_123"}";
            streamWriter.Write(json); 
            streamWriter.Flush();
            streamWriter.Close();
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Console.WriteLine(result);
            }
       }
链接地址: http://www.djcxy.com/p/45879.html

上一篇: Post JSON over HTTPS

下一篇: How to create a Google account programmatically?