We're building our proxy server and want all requests to ArcGIS service go through it.
From the Web I found that they support a method to config proxy rules:
/**
* Adds the given proxy rule to the proxy rules list: `esriConfig.request.proxyRules`.
*
* [Read more...](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-urlUtils.html#addProxyRule)
*
* @param rule An object specifying a URL that should use the proxy. See the object specification table below for the required properties of this object.
* @param rule.proxyUrl The URL of the proxy.
* @param rule.urlPrefix The URL prefix of the resources that should be accessed through the given proxy.
*
*/
addProxyRule(rule: urlUtilsAddProxyRuleRule): number;
But I can not find the API for iOS SDK. Could anyone has experience share with me how can I use proxy with the iOS ArcGIS SDK?
Many thanks!
Greetings,
The ArcGIS Maps SDK supports the proxy using the connectionProxyDictionary. You can use following code for setting the proxy with desired parameters at the start of the application. Then all data requests sent by the SDK will go through proxy.
let configuration = URLSessionConfiguration.default
configuration.connectionProxyDictionary = [
"HTTPSEnable": true,
"HTTPSProxy": "localhost",
"HTTPSPort": 9090
]
ArcGISEnvironment.urlSession = ArcGISURLSession { configuration }
If you would like to do the same for download requests then set ArcGISEnvironment.backgroundURLSession.
Hope this helps!
Regards,
Nimesh
Many thanks @NimeshJarecha
It seems that I need to update to the new ArcGIS version v200.x to use new API: ArcGISEnvironment.urlSession
Does the ArcGIS SDK v200.x support UIKit or it just supports SwiftUI?
Greetings,
Since you posted question under Swift Maps SDK Questions, I assumed that you are using the v200.x.
> Does the ArcGIS SDK v200.x support UIKit or it just supports SwiftUI?
The v200.x supports SwiftUI. However, iOS SDK supports converting UIKit views to SwiftUI. You'll find more information in UIKit Integration.
Hope this helps!
Regards,
Nimesh
Thanks for your information!
Sorry, but after I try to config the proxy, I found that my server is not a proxy server, it's just a proxy API. Here is how it works:
- Client (iOS, Android, web) sends a request to our API endpoint
- The request is sent to our API endpoint must follow this format: https://<our_api_endpint>?https://<arcgis_destination_url>. Example: https://myserver/api/maps/proxy?https://arcgisabc.maps.arcgis.com
- Our server will build and send a new request to ArcGIS online server after extracting the ArcGIS online destination endpoint (https://arcgisabc.maps.arcgis.com) from the request url, header, and parameters.
- When our server receives response from ArcGIS online server, it forwards the response to client
We follow this approach because we want to make sure all requests must go through our proxy API before reaching out to the ArcGIS online server.
Therefore, I tried to config map Portal base url by https://<our_api_endpint>?https<arcgisabc.maps.arcgis.com>, but it doesn't work.
I notice that the base map URL just supports those format:
/// The supported URL formats are:
/// - The URL of the portal (Example: https://www.arcgis.com)
/// - The URL of the portal rest end point (Example: https://www.arcgis.com/sharing/rest)
/// - The URL of the deprecated portal rest end point (Example: https://www.arcgis.com/sharing)
Here is my code to load the map portal:
struct ContentView: View {
private static let mapItem = PortalItem(portal: Portal(url: URL(string: "https://myserver/api/maps/proxy?https://arcgisabc.maps.arcgis.com")!), id: .baseMapId)
@State private var map = Map(item: mapItem)
var body: some View {
MapView(map: map)
}
}
Do you have any suggestion for me to load map from our custom URL https://<our_api_endpint>?https<arcgisabc.maps.arcgis.com>?
Or is there any way for me to modify the network request before ArcGIS SDK sends to server?
Thanks
Greetings
Unfortunately, the Swift SDK does not support the proxy url format you are using. However, it supports intercepting the requests/responses. You can create a custom object using DataTaskInterceptor and set it on the ArcGISURLSession.dataTaskInterceptor. You can do the same for download requests using DownloadTaskInterceptor.
Hope this helps!
Regards,
Nimesh
Hello,
I am trying your solution , but can you tell me what is the variable 'baseMapId'. What type of value it will store or assign.
If any fix solution or working solution is there please provide here.