Snažím se odeslat požadavek Export Web Map do mé AGS tiskové služby pomocí knihovny Esri Leaflet (verze 2.0.0 beta), ale řetězec GET požadavku je příliš dlouhý. Je možné spustit geoprocesní úlohu jako POST požadavek bez použití proxy stránky?
unfortunately this is kind of a 'you cant have your cake and eat it too' situation because you can't POST across domains when the server you're trying to reach doesn't support CORS.
you have two options.
1. if the print server actually supports CORS, you can accept the default constructor option and the plugin will automatically switch to a POST when the request is longer than 2000 characters
{ useCors: true }
2. if either the print server (or client browser) doesn't support CORS, you'll need to fall back on proxying the request to accomodate the security restriction.
see the conceptual article here for more information.
no problem at all.
i figured the server was up to the challenge, otherwise your jQuery call would have bombed out too
Thanks John Gravois, luckily the print server I'm using supports CORS and setting the useCors parameter to true worked.
In the meantime I have just recreated the print request with an Ajax call, which makes it possible to perform the GP task as a POST request. Would still like to know how to use the Esri Leaflet library with POST type GP requests.
jQuery Ajax
$.ajax({ url:'http://myserver/arcgis/rest/services/GP_Services/ExportWebMap/GPServer/Export%20Web%20Map/execute', type:'POST', dataType:'json', data:({ Format:"JPG", Layout_Template:"A4 Landscape", Web_Map_as_JSON:JSON.stringify(mapJSON), f:'json' }), success:function(response){ console.log(response.results[0].value.url); }, error:function(xhr, status, error) { console.log(error); } })
vs
Esri Leaflet GP task
var printService = L.esri.GP.service({ url: "http://myserver/arcgis/rest/services/GP_Services/ExportWebMap/GPServer/Export%20Web%20Map", async:false, useCors:false }); var printTask = printService.createTask(); printTask.setParam("Format", "JPG"); printTask.setParam("Layout_Template", "A4 Landscape"); printTask.setParam("f","json"); printTask.setParam("Web_Map_as_JSON",JSON.stringify(mapJSON)); printTask.setOutputParam('Output_File'); printTask.run(function(error, response, raw) { var printout = response.Output_File.url; console.log(printout); });
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.