0

I want to access to a .diff file of a private repository of GitHub. I have the following code, but doesn't work.

Dim myReq As HttpWebRequest = WebRequest.Create(url)
Dim netCred As NetworkCredential = New NetworkCredential("usr", "pass")
Dim credentials As ICredentials = netCred.GetCredential(url, "Basic")
myReq.Credentials = credentials
myReq.PreAuthenticate = True
Try
    Dim response As HttpWebResponse = CType(myReq.GetResponse(), HttpWebResponse)
Catch ex As System.Net.WebException
    MessageBox.Show(ex.Message)
End Try

There is something wrong? The message that the WebException contains is "Error in the remote server. (404) Not Found"

lsalvatore
  • 91
  • 1
  • 9
  • A 404 HTTP error is probably related to the `url`. What do you use as the `url`? We need more details on which web request is performed to help you. – mtheriault Nov 17 '16 at 14:34
  • An url with the following format github.com/[user]/[repo]/commit/[commitID].diff I can view the .diff with my usr and my pass in the browser. So i should access with the instance NetWorkCredential("myusr","mypass") – lsalvatore Nov 17 '16 at 14:40
  • I don't know a lot GitHub, Basic authentication is something supported? – mtheriault Nov 17 '16 at 14:47
  • I found this: https://developer.github.com/v3/auth/. The main difference is that the RFC requires unauthenticated requests to be answered with 401 Unauthorized responses. In many places, this would disclose the existence of user data. Instead, the GitHub API responds with 404 Not Found. – mtheriault Nov 17 '16 at 14:50
  • In this case, instead of using `HttpWebRequest.Credentials`. Craft your own `Authorization` header: see the following reponse for an example: http://stackoverflow.com/a/13956730/3508004. – mtheriault Nov 17 '16 at 14:53

0 Answers0