I've been working on an app for a presentation and we are using ArcGIS Online to geoenrich Canadian Census Dissemination Areas upon the users click. The only catch here is that some of the polygons are causing the request URLs to exceed the 2048 character limit in URLs. We are using the ESRI Proxy.ashx that you can get from GitHub and so i switched from a get request to a post request only the Post request doesn't seem to recognizes the variables being passed in the form data.
This first link is the request in Raw Format as captured by fiddler
The second link is the same request in WebForm view
This is the code i'm using to make the request to the proxy server, the proxy adds the token, after it gets the information from our ArcGIS Online account
var studyAreas = {
/* areaType: "RingBuffer",
bufferUnits: "esriKilometers",
bufferRadii: [2],*/
geometry: evt.graphic.geometry
}
var sa = JSON.stringify(studyAreas);
var dem = new Demographics;
var cats = dem.categories;
var av = '[';
for (l = 0; l < cats.length; l++) {
var curCat = dem[cats
] for (m = 0; m < curCat.length; m++) {
av += curCat
.varName; av += ',';
}
}
av = av.substr(0, av.length - 1);
av += ']';
request.post('/proxy/proxy.ashx?http://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich', {
data: {
StudyAreas: sa,
analysisVariables: av,
forStorage: false,
f: 'json'
}
});
Solved! Go to Solution.
I found the problem…when POSTing requests the GeoEnrichment service is much more picky about the incoming data types, previously study areas was sent as just an object, what I had missed and what is glossed over in the documentation is that studyAreas HAS to be an array of objects not just a single object. But the error message says nothing that would tell you that I just happened to stumble upon the answer almost by accident.
var mp = evt.graphic.geometry;
delete mp.type;
delete mp._partwise;
delete mp._ring;
delete mp._extent;
var studyAreas = {
geometry: mp
}
var saArray = [studyAreas];
var sa = JSON.stringify(saArray);
var dem = new Demographics;
var cats = dem.categories;
var av = '[';
for (l = 0; l < cats.length; l++) {
var curCat = dem[cats
] for (m = 0; m < curCat.length; m++) {
av += curCat
.varName; av += ',';
}
}
av = av.substr(0, av.length - 1);
av += ']';
xhr.post('/proxy/proxy.ashx?http://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich', {
data: {
studyAreas: sa,
analysisVariables: av,
forStorage: false,
f: 'json'
}
});
I found the problem…when POSTing requests the GeoEnrichment service is much more picky about the incoming data types, previously study areas was sent as just an object, what I had missed and what is glossed over in the documentation is that studyAreas HAS to be an array of objects not just a single object. But the error message says nothing that would tell you that I just happened to stumble upon the answer almost by accident.
var mp = evt.graphic.geometry;
delete mp.type;
delete mp._partwise;
delete mp._ring;
delete mp._extent;
var studyAreas = {
geometry: mp
}
var saArray = [studyAreas];
var sa = JSON.stringify(saArray);
var dem = new Demographics;
var cats = dem.categories;
var av = '[';
for (l = 0; l < cats.length; l++) {
var curCat = dem[cats
] for (m = 0; m < curCat.length; m++) {
av += curCat
.varName; av += ',';
}
}
av = av.substr(0, av.length - 1);
av += ']';
xhr.post('/proxy/proxy.ashx?http://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich', {
data: {
studyAreas: sa,
analysisVariables: av,
forStorage: false,
f: 'json'
}
});