Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET POSTCODE DATA WITHIN X DISTANCE IN MILES RETURNING ERROR 500 #47

Open
calmotuns opened this issue May 25, 2016 · 1 comment
Open

Comments

@calmotuns
Copy link

I have the below code:
it returns internal server error,
but whenever I post "http://uk-postcodes.com/postcode/nearest?postcode=SE146NS&miles=1&format=json" directly to the browser
before running the code it runs fine.
If I run the code without posting directly to browser it returns internal server error.
Please is there anything I'm doing wrong

Code:
string baseUrl = "http://uk-postcodes.com/postcode/nearest";
string restUrl = string.Format("{0}?postcode={1}&miles={2}&format=json", baseUrl, postcode, miles);

            HttpWebResponse response = null;
            HttpWebRequest request = WebRequest.Create(restUrl) as HttpWebRequest;
            request.Method = "GET";
            request.Accept = "application/json";
            request.ContentType = "application/json";

            using (response = request.GetResponse() as HttpWebResponse)
            {
                var reader = new StreamReader(response.GetResponseStream());

                if (response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Found)
                {
                    string responseContent = reader.ReadToEnd();

                    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                    postCodeWithRadiuses = javaScriptSerializer.Deserialize<List<PostCodeWithRadius>>(responseContent);

                }
                reader.Close();
            }
@calmotuns
Copy link
Author

the postcode variable is a real postcode amd the miles=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant