我很难从我的测试.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"。
答案 0 :(得分:-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
但正如我所说,它会产生同样的错误。让我知道,如果你搞清楚了......