首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从nse获取数据

无法从nse获取数据
EN

Stack Overflow用户
提问于 2020-09-10 11:59:26
回答 1查看 934关注 0票数 1

我正在尝试从nse印度获得选项链数据,但是我得到了下面的Exception

代码语言:javascript
复制
An error occurred while sending the request.
Unable to read data from the transport connection:
A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond.

下面是我的代码:

代码语言:javascript
复制
    public string getoptiondata()
            {
                var content = string.Empty;
                try
                {
                string url = "https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY";
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                request.UserAgent = ".NET Framework Test Client";
                request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
          
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        using (var sr = new StreamReader(stream))
                        {
                            content = sr.ReadToEnd();
                        }
                    }
                }
                }
    
                catch(Exception   e)
                {
    
                    using (StreamWriter sw = File.AppendText("`enter code here`ok.txt"))
                    {
                        sw.WriteLine("***********  Exception *********** \n");
                        sw.WriteLine(e.Message);
                    }
               
                }
    
    
                return content;
            }
EN

回答 1

Stack Overflow用户

发布于 2022-07-15 04:28:00

为SSl/TSL添加以下行:

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63829217

复制
相关文章

相似问题

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