簡體   English   中英

在iOS中從Visual Studio Xamarin進行Web服務調用

[英]Web service call from visual studio xamarin in ios

我們正在使用c#和Visual Studio 2017 for Xamarin開發iOS購物車應用程序。 我們正在使用其余的Web服務,在這里我不能稱之為Web服務。 當我調用Web服務時,出現錯誤[ConnectFailure(拒絕連接)]的響應為空。 我的問題是如何從本地URL獲取值,例如[ http:// localhost:56207 / api / Users / Raju / Password @ 123] 當我在瀏覽器中輸入此URL時,根據用戶和密碼驗證的不同,輸入的是真還是假。我請您幫助我解決此問題。我將代碼粘貼在下面:

 public class RestInterfaceImp : IRestLogin
    {

    HttpClient client;
    private const string WebServiceUrl = "http://localhost:56207/api/Users/Raju/Password@123";


    public async Task<List<User>> RefreshDataAsync()
    {

        try
        {
            var httpClient = new HttpClient();

            var resp = await httpClient.GetAsync(WebServiceUrl);


            if (resp.IsSuccessStatusCode)
            {
                var respStr = await resp.Content.ReadAsStringAsync();

               var listaAtletas = JsonConvert.DeserializeObject<List<User>>(respStr);

            }

        }
        catch (HttpRequestException e)
        {
            Debug.WriteLine(e.InnerException.Message);

        }
        return null;
    }

}

每當我們需要像您一樣向模擬器公開本地api時,我們都會使用ngrok:

https://github.com/inconshreveable/ngrok

由於某些原因,他們的網站現在關閉,因此有可能它們不再是問題,但這里是網址:

https://ngrok.com/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM