C# connecting to Dear System API and getting SaleList

249 views Asked by At

When I tried to get list of Sales from Dear Systems, I've got an error response of 500 Internal Server Error. I have this following codes.

            string xmlStringResult = string.Empty;
            string url = _cred.StoreName + "/SaleList";
            try
            {
                var req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "GET";
                req.ContentType = "application/xml";
                req.Headers.Add("api-auth-accountid", _cred.AccountId);
                req.Headers.Add("api-auth-applicationkey", _cred.APIKey);
                using (var resp = (HttpWebResponse)req.GetResponse())
                {
                    if (resp.StatusCode != HttpStatusCode.OK)
                    {
                        string message = String.Format("Call failed. Received HTTP {0}", resp.StatusCode);
                        AppendLog(string.Format("Error: {0}", message));
                        return xmlStringResult;
                    }

                    var sr = new StreamReader(resp.GetResponseStream());
                    xmlStringResult = sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                AppendLog(string.Format("Error: {0}", ex.Message));
            }
            return xmlStringResult;

Please advice and Thank you.

1

There are 1 answers

2
Windu Risky Adiatma On

Assuming the error was truly the response from the Dear Systems (not error caught in your catch block) :

Do you have control over the Dear Systems?

  • If so, I'd check from the server which hosts the Dear Systems, Internal Server Errors are usually logged in the Event Viewer (Start > Type 'Event Viewer').
  • If not, you should ask for help from those who has control over the system to check it for you.