Search code examples
c#httpwebrequestartifactoryjfrog-cli

Using C# HttpWebRequest with not typical URL


I am using the following function to receive an Artifacory repo mapping:

private string LoadHttpPageWithBasicAuthentication(string url, string username, string password)
{
    Uri myUri = new Uri(url);
    WebRequest myWebRequest = HttpWebRequest.Create(myUri);

    HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;

    NetworkCredential myNetworkCredential = new NetworkCredential(username, password);

    CredentialCache myCredentialCache = new CredentialCache();
    myCredentialCache.Add(myUri, "Basic", myNetworkCredential);

    myHttpWebRequest.PreAuthenticate = true;
    myHttpWebRequest.Credentials = myCredentialCache;

    WebResponse myWebResponse = myWebRequest.GetResponse();

    Stream responseStream = myWebResponse.GetResponseStream();

    StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);

    string pageContent = myStreamReader.ReadToEnd();

    responseStream.Close();

    myWebResponse.Close();

    return pageContent;
}

The URL that i am trying to pass looks like that -

http://ArtifactoryRepo?list&deep=1&listFolders=1&mdTimestamps=1

But from the result it seems that the request ignores part of the URL. The results that received are only for that part of the URL -

http://ArtifactoryRepo

I tried to split URL for two separate parameters but it doesn't worked

Any ideas ?

Thnaks


Solution

  • First there was a problem with credentials, so i used Convert.Tobase64string() function. And webReq.Method was not defined. Finally found that function to do the job.