Forum General

I need to pass a concatenated string as a web api url

abcdeveloperabcdeveloper INMember ✭✭

I am developing a PCL Project in Xamarin .I need to pass the IP Address of the device dynamically in the web api Url. My Code is as below:

In the code behind:

string IpAdd = txtIP.Text;

IPAddress = "http://" + IpAdd + ":8124/api/Items/";

MainViewModel.FinalIPAddress = IPAddress;

In my MainViewModel

public static string FinalIPAddress { get; set; }

public static readonly string WebServiceUrl = System.Net.WebUtility.UrlEncode(FinalIPAddress);

But I am unable to get through this. The below exception gets thrown.

**Exception thrown: 'System.InvalidOperationException' in Additional information: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
How to go about with this? Any help will be appreciated. Thanx in advance.


  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    If you step through the code, what is the value of WebServiceUrl just before the error? Sounds like it's malformed (but you know that).

    I also question why you're using the device's IP address in an HTTP call. Is the other end on the device? If not this doesn't make sense.
  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    What are you calling in ?

Sign In or Register to comment.