Azure API Management (1) 最近遇到的問題總結 Windows Azure Platform 系列文章目錄

  《Windows Azure Platform 系列文章目錄

 

  1.API Management Developer Portal進行測試的時候,報錯 "Unable to complete the request. Since the browser Initiates the request, it requires Cross-Origin Resource Sharing (CORS) enable on the server. Lean More.

  

  解決方法:

  點擊API Management,點擊Portal Overview,點擊Enable CORS,點擊Manually apply it on the global level。

  複製CORS policy,如下圖:

  

  然後點擊API Management,API

   

  在All APIs裏面,點擊Inbound processing,點擊Add Policy,在彈出的窗口中,選擇CORS

  

  在CORS配置裏,把我們在CORS policy裏面的設置複製到cors policy裏。

 

 

 

  2. API Management在API clone的時候,爲什麼backend地址會變化

  解答:API Management在開發的時候,最好設置爲backend + path

  舉個例子:我們請求的地址爲多個,如:

  -  https://myapi.chinacloudsites.cn/home/GetUser

  -  https://myapi.chinacloudsites.cn/home/GetStudent

  我們最好設置爲:

  -  backend設置爲: https://myapi.chinacloudsites.cn/home

  -  path分別設置爲/GetUser,/GetStudent

 

  在API裏,設置Setting裏面的Web service URL,設置請求路徑

  

 

  然後在不同的API裏,設置API的Frontend,如下圖:

  

  在URL裏,設置具體的path。如下圖:

  

 

 

  3.在HTTP Post裏,如何設置Request Body的類型?

  解答:可以通過設置Definition來實現。

  我們點擊APIs,點擊方法,點擊Definitions。如下圖:

  

 

  在Definitions裏,設置API的定義,如下圖:

  

 

  定義完畢後,選擇Frontend

  

 

  在彈出的窗口中,選擇Request,然後鼠標下拉,在Definition裏,選擇我們在上面新建的Definition

  

 

  設置完畢後,可以在API Management 的Developer Portal看到相關的Definition

 

 

  4.如何保護Azure API Management的後端服務,讓客戶端只能訪問Azure API Management,無法訪問後端的服務?

  解答:可以有多種方式實現:

  方式1:把後端的服務加入到VNet裏,然後讓API Management與VNet集成

  方式2:筆者的環境裏,後端服務是使用Azure App Service,可以可以先查看API Management的公網IP地址:

 

  請注意:

  API Managment的公網IP地址,在以下情況下會發生改變:

  •   服務被刪除,然後重新創建。
  •   服務訂閱被暫停或警告(例如,由於未付款),然後恢復。
  •   在該服務中添加或刪除 Azure 虛擬網絡。  
  •   API 管理服務在外部和內部 VNet 部署模式間切換。

 

  具體操作如下圖:

  

 

  然後在Azure App Service裏,設置IPV4防火牆規則。

  

 

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章