I am working on a program that automatically requests a website every 5 seconds. It has been working fine for the past few days, but today, when I just restarted it, it continues to throw System.ObjectDisposedExceptionon the line marked below. I should mention that accessing this URL through a browser on the same computer works fine.
The code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.bitstamp.net/api/ticker/");
request.Method = "GET";
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string resultString = reader.ReadToEnd();
return resultString;
}
}
}
catch (WebException ex)
{
}
Stack trace:
System.ObjectDisposedException occurred
_HResult=-2146232798
_message=Cannot access a disposed object.
HResult=-2146232798
IsTransient=false
Message=Cannot access a disposed object.
Object name: 'SslStream'.
Source=System
ObjectName=SslStream
StackTrace:
at System.Net.Security.SslState.ValidateCreateContext(Boolean isServer, String targetHost, SslProtocols enabledSslProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, Boolean remoteCertRequired, Boolean checkCertRevocationStatus, Boolean checkCertName)
InnerException:
Is there something I'm doing wrong? I don’t even get access to the response stream until usinghow can I delete it?
EDIT: Added URL tracing and tracing
source
share