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);
});
}
Solved! Go to Solution.
Robert,
Typing
http://localhost/proxy/proxy.ashx?http://localhost/FindNextVALUENumber/api/value
or
http://[mymachine]/proxy/proxy.ashx?http://[mymachine]/FindNextVALUENumber/api/value
Work fine.
It looks like https://js.arcgis.com is trying to open the link but it can't or it does not allowed.
The error persists pointing directly to my computer name instead of localhost
XMLHttpRequest cannot load http://jsancn-3/proxy/proxy.ashx?http://jsancn-3/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.
Jose,
This is how I have code in my app that calls a RESTfull web service without that error:
var requestHandle = esriRequest({
url: 'my web service url and endpoint',
content: {
ppin: ppin,
f: 'json'
},
handleAs: "json",
timeout: 10000
},{useProxy: true, usePost: false, disableIdentityLookup: true});
requestHandle.then(lang.hitch(this, function(taxReportJSON){
....
Hi Robert,
When do I have tdeclare a content part?
content: {
ppin: ppin,
f: 'json'
}
This is my code, let me update it to match yours:
esriConfig.defaults.io.alwaysUseProxy = true;
esriConfig.defaults.io.proxyUrl = "http://jsancn-3/proxy/proxy.ashx";
var url = "http://jsancn-3/FindNextVALUENumber/api/value";
var requestHandle = esriRequest({
"url": url,
handleAs: "json"
//callbackParamName: "jsoncallback"
});
requestHandle.then(requestSucceeded, requestFailed);
Jose,
If your web service does not take an input parameter then no you do not need the content part
It works now!
I just created an empty ASP.Net application, added html file "HtmlPage2.html", and used the "Internal Web Browser" to run the project. Selecting the HtmlPage2.html as "Set as Start Page" I was able to run it in Visual studio.
I am using URLs with my machine name instead of "localhost.
var requestHandle = esriRequest({
"url": url,
handleAs: "json"
}, {useProxy: true, usePost: false, disableIdentityLookup: true});
requestHandle.then(requestSucceeded, requestFailed);
Great, don't forget to mark this as answered.