Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:57:12+00:00 2026-05-23T10:57:12+00:00

I am using jQuery to get some data from an API. The stream reader

  • 0

I am using jQuery to get some data from an API.

The stream reader authenticates the calls to the api and gets the stream like this:

public string StreamManagerUrlHandler(string requestUrl)
{
    try
    {
        Uri reUrl = new Uri(requestUrl);
        WebRequest webRequest;
        WebResponse webResponse;

        webRequest = HttpWebRequest.Create(reUrl) as HttpWebRequest;
        webRequest.Method = WebRequestMethods.Http.Get;
        webRequest.ContentType = "application/x-www-form-urlencoded";
        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

        webRequest.Credentials = new NetworkCredential(
                ConfigurationManager.AppSettings["PoliceAPIUsername"].ToString(),
                ConfigurationManager.AppSettings["PoliceAPIPassword"].ToString());

        // Return the response. 
        webResponse = webRequest.GetResponse();

        using (StreamReader reader = new StreamReader(webResponse.GetResponseStream(), encode))
        {
            string results = reader.ReadToEnd();
            reader.Close();
            webResponse.Close();
            return results;
        }
    }
    catch (Exception e)
    {
        return e.Message;
    }
}

My Services look like this:

    [WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.Web.Script.Services.ScriptService]
[ScriptService()]
public class PoliceApi : System.Web.Services.WebService {

    public PoliceApi () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod(true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public string requestLocalCrime(string lat, string lng)
    {
        StreamManager streamMan = new StreamManager();
        return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=" + lat + "&lng=" + lng + "");
    }

    // Method for getting the data database was Last updated
    [WebMethod(true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public String requestLastTimeUpdated()
    {
        StreamManager streamMan = new StreamManager();
        return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/crime-last-updated");
    }

    // Method for getting the data database was Last updated
    [WebMethod(true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public String locateNeighbourhood(string lat, string lng)
    {
        StreamManager streamMan = new StreamManager();
        return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/locate-neighbourhood?q=" + lat + "%2C" + lng + "");
    }

    [WebMethod(true)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public string neighbourhoodTeam(string force, string neighbourhood)
    {
        StreamManager streamMan = new StreamManager();
        return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/" + force + "%2F" + neighbourhood + "%2F" + "people");
    }
}

And one of the jQuery ajax calls as an example looks like this:

// Getting last time the API data was updated
$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    url: "../police/PoliceApi.asmx/requestLastTimeUpdated",
    dataType: "json",
    success: function (data) {
        PoliceApp.mapForm.data('lastupdated', $.parseJSON(data.d).date);
    },
    error: function (res, status) {
            if (status === "error") {
                // errorMessage can be an object with 3 string properties: ExceptionType, Message and StackTrace
                var errorMessage = $.parseJSON(res.responseText);
                alert(errorMessage.Message);
            }
        }
});

Everything works fine locally. when I upload the stuff to the remote server I get:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

GET http://hci.me.uk/police/PoliceApi.asmx/requestLastTimeUpdated

401 Unauthorized

Prior to making the asmx services, I had them being used via aspx although this was causing some issues regarding performance and serialization, it used to work fine for some of the services. The API requires authentication for all get requests to work.

Demo link to this app

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:57:13+00:00Added an answer on May 23, 2026 at 10:57 am

    1) When, I try to test your webservice it tells me: “The test form is only available for requests from the local machine”

    Warning: Don’t leave your web.config like this after you are done testing

    Add this in to web.config so you can test the webservice outside of localhost:

       <configuration>
        <system.web>
        <webServices>
            <protocols>
                <add name="HttpGet"/>
                <add name="HttpPost"/>
            </protocols>
        </webServices>
        </system.web>
       </configuration>
    

    Then, go here to test: http://hci.me.uk/police/PoliceApi.asmx?op=requestLastTimeUpdated

    After testing, remove those lines from web.config for security reasons.

    2) Double-check your live web.config that the PoliceAPIUsername and PoliceAPIPassword
    are stored in AppSettings the same as in your local version of web.config

    3) Maybe the API you are requesting data from needs anonymous authentication to your live web services. I think anonymous users are allowed by default when testing locally.

    I found this article related to what I think might be your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fetching some value from another page using jQuery .get() like this <input
Im using jQuery getJSON method to get data from my database via some php
i am using jQuery to get some JSON data from a php file. my
I'm using JQuery's getJSON method to retrieve some data from an MVC controller. [AcceptVerbs(HttpVerbs.Get)]
I am using jQuery to get back some JSON data from the server. I
I have written some code using jQuery to use Ajax to get data from
I am using jQuery load, to load some data from an external file like
I am trying to get some data back from a server using jQuery $.getJSON
I use jQuery to get values of presaved elements from some websites, using paths
I am using jQuery's $.ajax method to retrieve some JSON from an API. Each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.