1

我正在使用以下函数来接收 Artifacory 回购映射:

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;
}

我试图传递的 URL 看起来像这样 -

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

但从结果来看,请求似乎忽略了部分 URL。收到的结果仅适用于 URL 的那部分 -

http://ArtifactoryRepo

我试图将 URL 拆分为两个单独的参数,但它不起作用

有任何想法吗 ?

纳克斯

4

1 回答 1

0

首先是凭据有问题,所以我使用了 Convert.Tobase64string() 函数。并且 webReq.Method 没有定义。终于找到了这个功能来完成这项工作。

于 2018-06-13T10:33:55.907 回答