如何使用vb.net从GitHub Enterprise下载all_user.csv报告并避免404错误?我可以使用Curl做到这一点

时间:2019-07-05 14:42:40

标签: vb.net curl github-enterprise

我正在尝试使用.net Framework 4.5.2通过vb.net下载GitHub Enterprise的all_users.csv文件,并收到以下错误消息: 远程服务器返回错误:(404)找不到。

我的代码是:

Module Module1 
 Sub Main() 
  Dim remoteUri As String = "https://ghe.webserver/stafftools/reports/all_users.csv" 
  Dim fileName As String = "all_users.csv" 
  Dim password As String = "PERSONALACCESSTOKEN" 
  Dim username As String = "USERNAME"

  System.Net.ServicePointManager.Expect100Continue = True 
  System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

  Dim client As New System.Net.WebClient 
  client.Credentials = New System.Net.NetworkCredential(username, password) 
  client.DownloadFile(remoteUri, fileName) 
 End Sub

End Module

错误发生在第client.DownloadFile(remoteUri, fileName)行,完全例外

System.Net.WebException was unhandled
  HResult=-2146233079
  Message=The remote server returned an error: (404) Not Found.
  Source=System
  StackTrace:
       at System.Net.WebClient.DownloadFile(Uri address, String fileName)
       at System.Net.WebClient.DownloadFile(String address, String fileName)
       at ConsoleApplication1.Module1.Main() in C:\Users\Admin\AppData\Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

但是,以下Curl命令有效(如此处所述:https://help.github.com/en/enterprise/2.17/admin/installation/site-admin-dashboard#reports): curl -L -u USERNAME:PERSONALACCESSTOKEN --insecure https://ghe.webserver/stafftools/reports/all_users.csv

0 个答案:

没有答案