I am new about Arcgis javascript API. While I am doing a sample application, I confused. I am analyzing this sample application.
This application is using the http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer/0 as FeatureLayer.
And using a proxy
esri.config.defaults.io.proxyUrl = "/proxy";
esri.config.defaults.io.alwaysUseProxy = false;
I created a new visual studio project and proxy pages. And I changed FeatureLayer and Base Map. Program is working. But I opened Mozilla Firebug and traced the traffic. My Application using multiple Http POST data, while zoom in. But Arcgis application Only 2 GET
This is my custom application screencast. (This is screenCast of my application https://i.sstatic.net/F1C17.png)
This is Arcgis Sample Application here
This is Arcsgis Application screencast:
-
I posted some info in a previous answer that you'll probably find helpful: gis.stackexchange.com/a/33177/124Derek Swingley– Derek Swingley2013年06月04日 15:43:39 +00:00Commented Jun 4, 2013 at 15:43
1 Answer 1
When you are sending a geometry to query a feature service, say for an intersection, the geometry is going to be large for a polygon. It will usually exceed the 2000 character limit for a get request. When it exceeds that limit, esri.request will send a post request, which requires the proxy, if you haven't specified that the server is CORS enabled.
However, I've noticed that sometimes adding a CORS server doesn't always work. (esri.config.defaults.io.corsEnabledServers.push("sampleserver1.arcgisonline.com");) It's safest to add to CORS and also have proxy...and let esri.request figure it out. It's better performance if the esri.request uses CORS.
Also to clarify, esri.request is being used by API calls like query a feature service.
http://help.arcgis.com/en/webapi/javascript/arcgis/jshelp/inside_esri_request.html Check out this help topic and in particular
Under the Hood: Determining Which Dojo Method is Used
esri.request uses the appropriate method to execute a request based on the target of the request and what the browser supports. The native method to do AJAX requests is to use XMLHttpRequest(XHR). Because there are subtle differences in how XHR is implemented across browsers, Dojo abstracts away and addresses cross-browser inconsistencies via dojo.xhrGet and dojo.xhrPost. Dojo also provides methods in the dojo.io namespace to do AJAX-style requests with JSONP and to use an iframe to upload files.
esri.request sits on top of the methods defined by Dojo to provide a clean, simple way to execute AJAX-style requests. Depending on the arguments passed to esri.request, different Dojo methods are used. The following pseudocode is a rough outline of how esri.request works.
JSONP:
If JSONP request
If target on same domain
Convert to JSON request
Else If CORS available
Convert to JSON request
Else
If request size is 2000 characters or less
Call dojo.io.script.get
Else
Convert to JSON request
JSON / XML / plain text:
If JSON / XML / PlainText request
If target not on same domain && CORS not available
Rewrite request url to use proxy
If request size is 2000 characters or less
Call dojo.xhrGet
Else
Call dojo.xhrPost
http://help.arcgis.com/en/webapi/javascript/arcgis/jshelp/inside_defaults.html
esri.config.defaults.io.corsEnabledServers
Add URLs for servers with cross-origin resource sharing enabled to this array. Cross-Origin Resource Sharing (CORS) allows web applications to bypass the browser's same origin policy file and access resources or services on different servers/domains. When both the web server and browser support CORS, esri.request will not use a proxy to perform cross-domain requests. The API includes some Esri servers by default so it's important to push items on to this array rather than overwriting it.
dojo.addOnLoad(pageReady);
function pageReady(){
esri.config.defaults.io.corsEnabledServers.push("servicesbeta.esri.com");
esri.config.defaults.io.corsEnabledServers.push("server.organization.com");
}
At version 2.8, the list contains the following servers by default:
'www.arcgis.com',
'tiles.arcgis.com',
'services.arcgis.com'
At version 3.1 the following domains were added to the list:
'static.arcgis.com',
'utility.arcgis.com',
'geocode.arcgis.com'
-
An important point of your answer is 2000 character limit for a get request. I understand that. When I open this[help.arcgis.com/en/webapi/javascript/arcgis/samples/… application in firebug, sending only One GET request to sampleserver1.arcgisonline.com. So T think the arcgis server rest service sending data less than 2000. But there are tons of lines on the map. My arcgis rest service gets lines but sending POST rewuest.barteloma– barteloma2013年05月30日 06:01:18 +00:00Commented May 30, 2013 at 6:01