0

我很难从我的测试 .net 应用程序向 airtable 添加记录。我能够很好地读取数据,但我不确定我是否正确格式化数据或没有在标题中添加内容。这是一个例子:

    Dim wHeader As WebHeaderCollection = New WebHeaderCollection()

    wHeader.Clear()
    wHeader.Add("Authorization: Bearer keynNkH2CywXXXXX")

    Dim sUrl As String = "https://api.airtable.com/v0/appGajjD5tTMmyCC5/Logs"

    Dim wRequest As HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(sUrl), HttpWebRequest)

    wRequest.ContentType = "application/json" ' I don't know what your content type is
    wRequest.Headers = wHeader

    wRequest.Method = "POST"
    wRequest.Accept = "*/*"
    Dim myData = "{""fields"": {""AppName"": ""test2"", ""Action"": ""hlkj"", ""User"": ""lhkjnjn""}}"

    wRequest.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)

    Dim wResponse As HttpWebResponse = DirectCast(wRequest.GetResponse(), HttpWebResponse)

    Dim sResponse As String = ""

    Using srRead As New StreamReader(wResponse.GetResponseStream())
        sResponse = srRead.ReadToEnd()
    End Using
    MessageBox.Show(sResponse)

我不断收到的错误是“422 Unprocessable Entity”。

4

1 回答 1

-1

我遇到了同样的问题。编写了与您类似的代码,出现该错误。然后尝试将其合并:https ://github.com/ngocnicholas/airtable.net 到我的项目中,但得到同样的错误。如果您想尝试将该客户端合并到您的项目中,这是从 vb 调用它的方法:

 Protected Async Sub t2Async()
        Dim myFields As Fields = New Fields()
        myFields.AddField("Name", "Some value")
        Dim myAirtableBase As AirtableBase = New AirtableBase(appKey, baseId)
        Dim myTask As Task(Of AirtableCreateUpdateReplaceRecordResponse) = myAirtableBase.CreateRecord("Clients", myFields, False)
        Dim response = Await myTask
    End Sub

但正如我所说,它会产生同样的错误。让我知道,如果你想出什么...

于 2017-05-19T08:28:19.053 回答