我正在尝试从nse印度获得选项链数据,但是我得到了下面的Exception
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.下面是我的代码:
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;
}发布于 2022-07-15 04:28:00
为SSl/TSL添加以下行:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;https://stackoverflow.com/questions/63829217
复制相似问题