-1

I have a project which is about RESTful API and I have as a property the basic URL, on which I need to add parts each time (that's in my methods). I need (a) to declare the default (unchanged) path, and then (b) some help on how do I add to the URL. Example:

    public partial class APIParamaters
{
    public System.Uri URL { get; set; } = (System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api";   //throws error !!!
}

This is throwing an error and I don't know how to correct. Also, how do I later add to the URL, for example, I am trying

    class MyTest
{
    public string SpecialPart = "Excellent";

    public APIParamaters myParams = new APIParamaters
    {
        URL = URL + SpecialPart + "FirstCall",     //trying to do: "http://192.100.106.657:8811/some/part/here/version1/api/Excellent/FirstCall"
        SomethingElse = "Ok"
        //etc..
    };
}
Nick
  • 483
  • 1
  • 6
  • 15
  • Does this answer your question? [Path.Combine for URLs?](https://stackoverflow.com/questions/372865/path-combine-for-urls) – Sinatr Dec 17 '19 at 15:30
  • And [here](https://stackoverflow.com/q/28418671/1997232) is duplicate for error you get. – Sinatr Dec 17 '19 at 15:35
  • Does this answer your question? [Error when compiling - 'Cannot implicitly convert type 'string' to 'System.Uri'](https://stackoverflow.com/questions/28418671/error-when-compiling-cannot-implicitly-convert-type-string-to-system-uri) – JSteward Dec 17 '19 at 15:39

1 Answers1

2

The following code means (cast this string as System.Uri) but string can not be cast as System.Uri:

(System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api";

You should instantiate System.Uri:

public System.Uri URL { get; set; } = new System.Uri("http://192.100.106.657:8811/some/part/here/version1/api");
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • Thank you very much, worked perfectly. Any idea on how do I add parts at the end of it (refering to the "public APIParamaters myParams = new APIParamaters" part of the question). Thank you very much ! – Nick Dec 17 '19 at 15:35