簡體   English   中英

將httpwebrequest發布到渠道顧問

[英]post httpwebrequest to channel advisor

我正在嘗試從channeladvisor電子商務獲取新令牌,我正在使用此代碼

       // HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.channeladvisor.com/oauth2/token");
       var request=HttpWebRequest.Create("https://api.channeladvisor.com/oauth2/token");
        WebResponse response = null;
        string responseString = string.Empty;
        try
        {
        //    request.Timeout = 300000;
          //  request.KeepAlive = false;
          //request.ContentType = "application/json";                
            request.UseDefaultCredentials = true;
            string credentials = applicationid + ":" + sharesecret;
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(credentials);
            string base64 = Convert.ToBase64String(bytes);
            request.Headers["Authorization"] = "Basic " + base64;
            request.ContentType = " application/x-www-form-urlencoded";

              ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 |
                                    SecurityProtocolType.Tls12;

            request.Method = "Post";
           // var stringContent = new StringContent("grant_type=refresh_token&refresh_token=" + refreshToken);
            request.ContentLength = System.Text.Encoding.ASCII.GetByteCount("grant_type=refresh_token&refresh_token=" + refreshToken);
            byte[] buffer = System.Text.Encoding.ASCII.GetBytes("grant_type=refresh_token&refresh_token=" + refreshToken);
           // string result = System.Convert.ToBase64String(buffer);
            Stream reqstr = request.GetRequestStream();
            reqstr.Write(buffer, 0, buffer.Length);
            reqstr.Close();
            response = (HttpWebResponse)request.GetResponse();
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                responseString = reader.ReadToEnd();
            }
        }
        catch (Exception)
        {

            throw;
        }

但我不斷收到錯誤

System.Net.WebException:請求已中止:無法創建SSL / TLS安全通道。 有什么問題 謝謝

試試這個添加了這一行:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons

從這里參考更多,這可以幫助您很多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM