我正在使用 Balanced Payments API 并试图弄清楚如何创建客户。
https://docs.balancedpayments.com/current/api.html?language=bash#creating-a-customer
该地址作为对象传递,尽管我不熟悉如何传递字符串以外的任何内容。这是我到目前为止成功传递姓名和电子邮件地址的代码:
Dim request As WebRequest = WebRequest.Create("https://api.balancedpayments.com/v1/customers")
request.Method = "POST"
' get this information from settings in your web config.
Dim userName As String = "API KEY GOES HERE"
Dim credentials As String = Convert.ToString(userName & Convert.ToString(":"))
request.Headers("Authorization") = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials))
Dim postData As String = "name=John Doe&email=jdoe@domain.com"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
' create a data stream.
dataStream = response.GetResponseStream()
' create a stream reader.
Dim reader As New StreamReader(dataStream)
' read the content into a string
Dim serverResponse As String = reader.ReadToEnd()
' clean up.
reader.Close()
dataStream.Close()
response.Close()