Skip to content

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

Description

@calmotuns

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();
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions