用Macbook開發案頭應用,使用Alamofire連結.Net Core Webapi的注意事項!

來源:互聯網
上載者:User

標籤:fir   怎麼   apple   響應   build   字型   server   dict   ati   

------------https方式-----------------------

因為Swift9之後提供者只能使用https,所以在後台加入pfx檔案(怎麼產生,自行百度吧)
1.將pfx放在項目根目錄下面。
2.將Program的啟動項改為

// WebHost.CreateDefaultBuilder(args)// .UseKestrel(option => {// option.Listen(System.Net.IPAddress.Any, 5001, (lop) => {// lop.UseHttps("server.pfx", "111");// });// })// .UseUrls("https://*:5001")// .UseContentRoot(Directory.GetCurrentDirectory())// .UseIISIntegration()// .UseStartup<Startup>()// .Build();3.後台改造完畢。4.Swift中使用Alamofire調用, “ ATS failed system trust”, 經百度,蘋果公司對http的訪問管控越來越嚴,此處必須是CA認證,在網上申請認證又要網域名稱,因為是本地開發項目,還沒有相關資料,所以放棄這種方式。  -----------http方式------------------------ 隨後在網上又找了可以本地http的方式 1.在info.plist中增加紅色字型部分

    <key>NSPrincipalClass</key>

    <string>NSApplication</string>

    <key>NSAppTransportSecurity</key>

    <dict>

        <key>NSAllowsArbitraryLoads</key>

        <true/>

    </dict>

</dict>

</plist>

2.將.Net Core代碼再改回去(如果你安裝上面的方式修改的話)

WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build();3.在swift中用一下代碼測試

        Alamofire.request("http://localhost:5000/api/******/Gettables").responseJSON { response in

            print(response.request)  // 原始的URL請求

            print(response.response) // HTTP URL響應

            print(response.data)     // 伺服器返回的資料

            print(response.result)   // 響應序列化結果,在這個閉包裡,儲存的是JSON資料

 

            if let JSON = response.result.value {

                print("JSON: \(JSON)")

            }

        }

  

用Macbook開發案頭應用,使用Alamofire連結.Net Core Webapi的注意事項!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.