System.Net.Sockets.SocketException: De externe host heeft een verbinding verbroken

I'm not able to connect to the API through my ASP.NET application. I get the exception detail: "System.Net.Sockets.SocketException: De externe host heeft een verbinding verbroken".

I've tried several types of code to try to connect without success. (see below).
Any suggestions?

Code 1:
string orderUrl = string.Format("https://api.webshopapp.com/nl/orders.json?sinceId=0", apiKey, apiSec);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(orderUrl);
            request.Method = "GET";
            //request.Credentials = new NetworkCredential(apiKey, apiSec);
            String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(apiKey + ":" + apiSec));
            request.Headers.Add("Authorization", "Basic " + encoded);
            //request.PreAuthenticate = true;
            string test = String.Empty;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                test = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
            }
            dynamic orders = JsonConvert.DeserializeObject(test);


Code 2:
string orderUrl = string.Format("https://api.webshopapp.com/nl/orders.json?sinceId=0", apiKey, apiSec);
            string content;
            using (WebClient client = new WebClient())
            {
                client.Credentials = new NetworkCredential(apiKey, apiSec);
                content = client.DownloadString(orderUrl);

            }
            dynamic orders = JsonConvert.DeserializeObject(content);

6 comments

Sign In or Register to comment.