Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you post an object using WebRequest.Create?
    text
    copied!<p>I am working with the Balanced Payments API and trying to figure out how to create a customer.</p> <p><a href="https://docs.balancedpayments.com/current/api.html?language=bash#creating-a-customer" rel="nofollow">https://docs.balancedpayments.com/current/api.html?language=bash#creating-a-customer</a></p> <p>The address is passed as an object, though I am unfamiliar with how to pass anything other than a string. Here is the code I have so far which successfully passes a name and email address:</p> <pre><code> 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 &amp; Convert.ToString(":")) request.Headers("Authorization") = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials)) Dim postData As String = "name=John Doe&amp;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() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload