Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Cannot call web api hosted in IIS server from xamarin forms .

$
0
0

I have hosted my web api in IIS server in my system.

When I try to call api from xamarin forms I am getting Errr: Connect failure(Network is un reachable) exception.

Can any one tell me , Is there anything configuration setting need to be done in xamarin projects to call api from xamarin forms.
On button click I am calling api.

When I call api I am getting following error.

System.Net.WebException: Error: ConnectFailure (Network is unreachable)

Please find my entire code behind code.

public partial class MainPage : ContentPage
{
private MediaFile _mediaFile;
public MainPage()
{
InitializeComponent();
}

    private async void PickPhoto_Clicked(object sender, EventArgs e)
    {
        await CrossMedia.Current.Initialize();
        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await DisplayAlert("No Pick Photo", ":( No PickPhoto available", "Ok");
            return;
        }
        _mediaFile = await CrossMedia.Current.PickPhotoAsync();
        if (_mediaFile == null)
        {
            return;
        }
        LocalPathLabel.Text = _mediaFile.Path;
        FileImage.Source = ImageSource.FromStream(() =>
          {
              return _mediaFile.GetStream();
          });
    }

    private async void UploadPhoto_Clicked(object sender, EventArgs e)
    {
        try
        {
            var content = new MultipartFormDataContent();
            content.Add(new StreamContent(_mediaFile.GetStream()), "\"file\"", $"\"{_mediaFile.Path }\"");

            var uploadBaseAddress = "http://10.243.243.33:84/api/Files/Upload";

            var httpClient = new HttpClient();
            var httpResponseMessage = await httpClient.PostAsync(uploadBaseAddress, content);
            RemotePathLabel.Text = await httpResponseMessage.Content.ReadAsStringAsync();
        }
        catch (Exception ex)
        {
            RemotePathLabel.Text = ex.Message;
        }

    }

}

PickPhoto_Clicked event handler is used to pick an image from gallery.

UploadPhoto_Clicked is called when I click on UploadPhoto button.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>