2

'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

http://imgur.com/xlWfh6F

The second link is the same request in WebForm view

http://imgur.com/3fPoHlL

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[l]]
    for (m = 0; m < curCat.length; m++) {
        av += curCat[m].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'
    }
});
  • 1
    using esriRequest should allow the API do determine whether to GET or POST as appropriate on the fly. – John Gravois Oct 1 '14 at 20:45
2

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[l]]  
            for (m = 0; m < curCat.length; m++) {  
                av += curCat[m].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', {   
        handleAs: 'json',    
        data: {  
                studyAreas: sa,  
                analysisVariables: av,  
                forStorage: false,  
                f: 'json'  
            }  
        });  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.