私は新しいことを聞き、人々がどのように喜んで助けてくれるのか本当に好きです。学生情報を管理するアクセスデータベースと、学生が基本情報を登録する別のWebサイトがあります。私は、私のデータベースにインポートすることができるように学生情報のxmlまたはjson形式を取得するAPIを作成します。以下は、APIのカールです: カール-F "APIキー= d8a40f77-69b5-4ef7-b554-d8f86382101c" "http://ktsstf.org/call.php?apicall=registration.data&apiDataType=xml"VBA投稿のリクエストKeyを必要とするAPIから
curlコマンドが問題なく実行されます。しかし、VBAで私のコードは私にエラーを与え続けて「失敗:間違ったAPIキー」を以下 はコードで、あなたたちが私に-Fパラメータは、HTTP POSTデータのためである
Public Sub getscholar()
Dim webServiceURL As String
Dim actionType As String
Dim targetWord As String
Dim actionType2 As String
Dim targetWord2 As String
webServiceURL ="http://ktsstf.org/call.phpapicall=registration.data&apiDataType=xml"
actionType = "Content-Type"
targetWord = "text/xml"
actionType2 = "Authorization"
'targetWord2 = "apikey" + "d8a40f77-69b5-4ef7-b554-d8f86382101c"
targetWord2 = "Basic " & ("d8a40f77-69b5-4ef7-b554-d8f86382101c")
' use late binding
With CreateObject("Microsoft.XMLHTTP")
.Open "POST", webServiceURL, False
.setRequestHeader actionType, targetWord
.setRequestHeader actionType2, targetWord2
.send
If .Status = 200 Then
Debug.Print .responseText
MsgBox .GetAllResponseHeaders
Else
MsgBox .Status & ": " & .StatusText
End If
End With
End Sub