404使用cURL PUT Pivotal Tracker时

时间:2015-11-26 10:16:43

标签: vb.net rest curl

我正在尝试从Pivotal Tracker REST V5 API将cURL字符串转换为VB.NET,请参阅https://www.pivotaltracker.com/help/api/rest/v5#Story中的以下示例:

export TOKEN='your Pivotal Tracker API token'
export PROJECT_ID=99

curl -X PUT -H "X-TrackerToken: $TOKEN" -H "Content-Type: application/json" -d '{"current_state":"accepted","estimate":1,"name":"Exhaust ports have ray shielding"}' "https://www.pivotaltracker.com/services/v5/projects/$PROJECT_ID/stories/555"

我正在尝试使用cURL将样本数据传输到Pivotal Tracker。一旦工作,我将设置一个ASP.NET错误提交表单。

这是我的VB.NET按钮点击代码:

Protected Sub submitinfo_Click(sender As Object, e As EventArgs) Handles submitinfo.Click

    Dim wHeader As WebHeaderCollection = New WebHeaderCollection()

    wHeader.Clear()
    wHeader.Add("X-TrackerToken: [***MY TOKEN***]")

    ' variables to store parameter values
    Dim surl As String = "https://www.pivotaltracker.com/services/v5/projects/1398094/stories"
    Dim data As String = "{'current_state':'accepted','estimate':1,'name':'Exhaust ports have ray shielding'}"

    ' create the POST request
    Dim webRequest__1 As HttpWebRequest = DirectCast(System.Net.WebRequest.Create(surl), HttpWebRequest)
    webRequest__1.Method = "PUT"
    webRequest__1.Headers = wHeader
    webRequest__1.ContentType = "application/json"

    '  This actually does the request and gets the response back
    Dim resp As HttpWebResponse = DirectCast(webRequest__1.GetResponse(), HttpWebResponse)
    Dim sResponse As String = ""



    ' POST the data
    Using requestWriter2 As New StreamWriter(webRequest__1.GetRequestStream())
        requestWriter2.Write(data)
    End Using


    Dim responseData As String = String.Empty

    Using responseReader As New StreamReader(webRequest__1.GetResponse().GetResponseStream())
        ' dumps the HTML from the response into a string variable
        responseData = responseReader.ReadToEnd()
    End Using

    Label1.Text = responseData

End Sub

我试图改编代码:

我收到404错误 - 但地址是正确的!我把头发拉出来,请帮忙!

非常感谢!

克里斯

0 个答案:

没有答案