如何将此cURL命令转换为VB?

时间:2016-11-21 15:53:42

标签: vb.net curl httpwebrequest

我正在尝试将以下cURL命令转换为将GitHub中的.diff内容传递给VB:

    curl -H 'Authorization: token myGitHubToken' -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/[USR]/[REPO]/commits/[COMMITID]

cURL工作正常。我在VB中使用HttpWebRequest的代码是

    Dim url As New Uri("https://api.github.com/repos/[USR]/[REPO]/commits/[COMMITID]")
    Dim myReq As HttpWebRequest = HttpWebRequest.Create(url)
    SetAllowUnsafeHeaderParsing20()
    myReq.Headers.Add("Authorization: token myGitHubToken")
    myReq.Accept("application/vnd.github.v3.diff")
    myReq.KeepAlive = False
    Dim response As HttpWebResponse = CType(myReq.GetResponse(), HttpWebResponse)

但是在GetResponse中,会向我发送WebException

  

“远程服务器返回错误:(403)禁止”

我的翻译好吗?有什么不对吗?

0 个答案:

没有答案