I am having a hard time getting this POST to work.
First - this is a CURL command that someone gave me to SEND A TEXT message...
And this is the code in VB .Net attempting the same POST.Code:curl -X POST https://app.xxxxxxx.com/api/v3/xxxxxxxx -H "accept: application/json" -H "authorization: Basic YTA1MThkNjZkYm...azNhamNod0VRUGRhdk1aZw==" -H "Content-Type: application/json" -d "{\"sms\": {\"body\": \"TEST\",\"phone_numbers\": [\"1112223333\"]}}"
Error I get is: {"The underlying connection was closed: An unexpected error occurred on a send."}Code:Function sendRequest(apikey As String, url As String, actionttype As String, actionstring As String) As String Dim postString As String = actionstring ' postXml.Declaration.ToString & postXml.ToString Dim urlString As String = url.Replace("Action", actionttype) Dim request As HttpWebRequest = DirectCast(WebRequest.Create(urlString), HttpWebRequest) request.Method = "POST" request.AllowWriteStreamBuffering = False request.PreAuthenticate = True request.Headers.Add("Authorization", "Basic YTA1MThkNj.....hamNod0VRUGRhdk1aZw==") request.Accept = "application/json" request.ContentType = "application/json" request.ContentLength = postString.Length request.KeepAlive = True Dim outputstream As Stream = request.GetRequestStream() '<<<< ****** blows up here Dim postBytes As Byte() = Encoding.ASCII.GetBytes(postString) outputstream.Write(postBytes, 0, postBytes.Length) Dim response As WebResponse = request.GetResponse() Dim datastream As Stream = response.GetResponseStream() Dim datareader As StreamReader = New StreamReader(datastream) Dim textstring As String = datareader.ReadToEnd() outputstream.Close() response.Close() Return textstring End Function
Anyone have experience with BASIC Authentication?
I think that the token I'm using that works for the other person, is somehow specific to when they used an api_key and secret to get that token from a "test" website for checking out how the API works.
I think I need to use the api key and secret to get my own token.
But then again, they say this token they got over 24 hours ago is still working. And it's even still working after they used the key and secret to get a new token.
TIA!




Reply With Quote