Skip to main content

HTTP 401 'Unauthorized' In SharePoint Hosted app

Can we use third party custom Web services in SharePoint-hosted app on Office 365?

My requirement is to get an item from Casio Web server and display in SharePoint Environment (Office 365) using SharePoint Hosted app.

But I'm receiving this error:

Status code: 401,The remote server returned the following error while establishing a connection - 'Unauthorized'

Here is my code:

$(document).ready(function () {

    (function () {
        alert('Executed');
        var context = SP.ClientContext.get_current();
                
        var request = new SP.WebRequestInfo();
        
        request.set_url(
            "http://Otherdomain/BookingService.asmx"
            );        
        request.set_method("GET");

        request.set_headers({ "Accept": "application/json;odata=verbose" });
        var response = SP.WebProxy.invoke(context, request);

        context.executeQueryAsync(successHandler, errorHandler);

        function successHandler() {
            if (response.get_statusCode() == 200) {
                // Load the OData source from the response.
                var responseData = JSON.parse(response.get_body());
                // log this to console so you can inspect it
                console.log(responseData)
            }
            else {
                var errordesc = "Status code: " + response.get_statusCode();
                errordesc += "\n" + response.get_body();
                alert(errordesc);
               // console.log(errordesc)
                txtOutput.text = errordesc;
            }
        }
        function errorHandler() {
            //console.log(response.get_body());
            txtOutput.text = 'Error';
        }
    })();

});

Can we give the Network Credentials details on SharePoint-hosted app development?