"Unable to load /proxy/?http://localhost Statu 404

5506
15
Jump to solution
12-07-2016 12:25 PM
JoseSanchez
Occasional Contributor III

Hello everyone,

I am getting the following error message

"Unable to load /proxy/?http://localhost/FindNextVALUENumber/api/value status: 404"

when running this sample:

https://developers.arcgis.com/javascript/3/jssamples/data_requestJson.html

 

When I pass these URLs, the first one works fine but the second one fails

url = "http://localhost:59297/api/value";   <ç========WORKS FINE – it is the Visual Studio 2012 proejct

 

Or

url = "http://localhost/FindNextVALUENumber/api/value"; <ç==== FAILS – runs from IIS

The second URL is the IIS Application pointing to the same folder.

 

I am using the proxy server from this sample: https://github.com/Esri/resource-proxy

 

I tested both url and they work fine with the proxy:

http://localhost/proxy/proxy.ashx?http://localhost:59297/api/value

 http://localhost/proxy/proxy.ashx? http://localhost/FindNextVALUENumber/api/value

 

 

Here is the proxy.config file

 <ProxyConfig allowedReferers="*"   mustMatch="true">

   <serverUrls>

     <serverUrl url="http://localhost:61004"

                 matchAll="true"/>

 

     <serverUrl url="http://localhost:59297"

               matchAll="true"/>

 

     <serverUrl url="http://localhost"

                   matchAll="true"/>

   </serverUrls>

</ProxyConfig>

 

 

My code:

            esriConfig.defaults.io.proxyUrl = "/proxy/";

 

           var url = "http://localhost:59297/api/value";

           url = "http://localhost/FindNextVALUENumber/api/value";

 

           dom.byId("url").value = url;

           dom.byId("content").value = "";

           //handle the Go button's click event

           on(dom.byId("submitRequest"), "click", getContent);

           var serviceDescriptionStr = "";

           function getContent() {

               var result = "";

               var contentDiv = dom.byId("content");

               contentDiv.value = "";

               domClass.remove(contentDiv, "failure");

               dom.byId("status").innerHTML = "Downloading...";

 

               var requestHandle = esriRequest({

                    "url": url,

                   handleAs: "json"

 

                 });

                                       

               requestHandle.then(

                                 function (response) {

 

                                     console.log("Data: ", response);

                                     dojoJson.toJsonIndentStr = " ";

                                     console.log("Success: ", response);

                                 },

                                 function (error) {

                                      console.log("Error: ", error.message);

                                     alert(error.message);

                                });

            }

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Great, don't forget to mark this as answered.

View solution in original post

0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Jose,

   If you can not get the to run in a browser without running the service from your visual studio that is what you need to focus on first. The fact that you can not get your second url to work from the browser is an issue that will stop you in your tracks until you get that fixed (forget all the js and proxy stuff until you get that resolved).

0 Kudos
JoseSanchez
Occasional Contributor III

Thank you Robert

I am able to run "http://localhost:59297/api/value   and http://localhost/FindNextVALUENumber/api/value  in my Goodle browser and it works fine.

I also added  alwaysUseProxy and updated proxyUrl with the whole path.

esriConfig.defaults.io.alwaysUseProxy = false;

esriConfig.defaults.io.proxyUrl = "http://localhost/proxy/proxy.ashx";

This is the error message I am getting:

XMLHttpRequest cannot load http://localhost/proxy/proxy.ashx?http://localhost/FindNextValueNumber/api/value. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:59297' is therefore not allowed access.
init.js:89 n {message: "Unable to load http://localhost/proxy/proxy.ashx?h…localhost/FindNextVALUENumber/api/value status: 0", response: Object, status: 0, responseText: "", xhr: XMLHttpRequest…}w @ init.js:89(anonymous function) @ init.js:88c @ init.js:103d @ init.js:103resolve.callback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105(anonymous function) @ init.js:92h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109n @ init.js:138f @ init.js:143

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

  what does your proxy.config look like?

0 Kudos
JoseSanchez
Occasional Contributor III

Hello

Here is a copy of the proxy.config

<?xml version="1.0" encoding="utf-8" ?>

<ProxyConfig allowedReferers="*" mustMatch="true">

<serverUrls>

<serverUrl url="http://services.arcgisonline.com"

matchAll="true"/>

<serverUrl url="http://gisweb.miamidade.gov"

matchAll="true"/>

<serverUrl url="http://localhost:59297"

matchAll="true"/>-->

<serverUrl url="http://localhost/proxy/"

matchAll="true"/>

<serverUrl url="http://localhost/FindNextvalueNumber/"

matchAll="true"/>

<serverUrl url="http://localhost/proxy/"

matchAll="true"/>

<serverUrl url="http://[mycomputername]/FindNextvalueNumber/"

matchAll="true"/>

 

 

</serverUrls>

</ProxyConfig>

<!-- See https://github.com/Esri/resource-proxy for more information -->

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

   your urls used in your code and your proxy.config are CaSe sensitive so 

<serverUrl url="http://localhost/FindNextvalueNumber/"
matchAll="true"/>

does not match

http://localhost/FindNextVALUENumber/api/value

0 Kudos
JoseSanchez
Occasional Contributor III

Same error. See below:

XMLHttpRequest cannot load http://localhost/proxy/proxy.ashx?http://localhost/FindNextAASISNumber/api/aasis. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:59297' is therefore not allowed access.

init.js:89 n_ssl: undefinedlog: undefinedmessage: "Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0"response: ObjectresponseText: ""stack: "Error: Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/aasis status: 0↵    at new n (https://js.arcgis.com/3.18/init.js:111:353)↵    at XMLHttpRequest.f (https://js.arcgis.com/3.18/init.js:142:454)"status: 0xhr: XMLHttpRequest__proto__: Errorw @ init.js:89(anonymous function) @ init.js:88c @ init.js:103d @ init.js:103resolve.callback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105c @ init.js:104d @ init.js:103reject.errback @ init.js:105(anonymous function) @ init.js:92h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109a @ init.js:108h @ init.js:107k @ init.js:107w.reject @ init.js:109n @ init.js:138f @ init.js:143

 

  1. n
    1. _ssl:undefined
    2. log:undefined
    3. message:"Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0"
    4. response:Object
    5. responseText:""
    6. stack:"Error: Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0 at new n (https://js.arcgis.com/3.18/init.js:111:353)   at XMLHttpRequest.f (https://js.arcgis.com/3.18/init.js:142:454)"
    7. status:0
    8. xhr:XMLHttpRequest
    9. __proto__:Error
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

Origin 'http://localhost:59297' is therefore not allowed access. So i am confused is your app running in Visual Studio?

My personal preference is to never use localhost in my urls. If you know your machine name then use it instead. When developing a RESTfull web service get it working in the web browser and once you are satisfied then deploy it to your web server for use in developing your js code.

0 Kudos
JoseSanchez
Occasional Contributor III

Hi Robert,

I created an "HtmlPage2.html" in my current Visual Studio project to test the code.

Now I just copied this page "HtmlPage2.html" to a new folder, and opened it with Google Chrome.

When I open the page this is the error I am getting:

XMLHttpRequest cannot load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value.

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

  1. n
    1. _ssl:undefined
    2. log:undefined
    3. message:"Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0"
    4. response:Object
    5. responseText:""
    6. stack:"Error: Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0 at new n (https://js.arcgis.com/3.18/init.js:111:353)   at XMLHttpRequest.f (https://js.arcgis.com/3.18/init.js:142:454)"
    7. status:0
    8. xhr:XMLHttpRequest
    9. __proto__:Error

 

 

 

HtmlPage2.html:111 Error: Unable to load http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value status: 0

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

   What happen when you just put http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value in your browsers addresbar and hit enter?

0 Kudos