首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将httpwebrequest发布到渠道顾问

将httpwebrequest发布到渠道顾问
EN

Stack Overflow用户
提问于 2018-07-19 17:08:10
回答 1查看 111关注 0票数 0

我正在尝试从channeladvisor电子商务获取新令牌我正在使用以下代码

代码语言:javascript
复制
       // 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安全通道。问题出在哪里?谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-07-19 19:59:40

尝试添加这一行:

代码语言:javascript
复制
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons

Refer More From Here which help you alot

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51418590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档