CodeJunky
asked on
Post WebRequest in SSIS failing
SSIS on SQL Server 2016 instance
Web Request Task is being used to upload data to a website. Current coding works with existing address and key.
The new address and key is failing with a code of 4, indicating lost connection when GetRequestStream. I wrote a standalone VB.NET app with exact code and ran it without errors. I placed the code below, without the actual address and key of course. The failure occurs at this section of the code….
Dim NewStream As Stream = REQUEST.GetRequestStream()
NewStream.Write(bytes, 0, bytes.Length)
NewStream.Close()
Web Request Task is being used to upload data to a website. Current coding works with existing address and key.
The new address and key is failing with a code of 4, indicating lost connection when GetRequestStream. I wrote a standalone VB.NET app with exact code and ran it without errors. I placed the code below, without the actual address and key of course. The failure occurs at this section of the code….
Dim NewStream As Stream = REQUEST.GetRequestStream()
NewStream.Write(bytes, 0, bytes.Length)
NewStream.Close()
Private Function SEND_DATA_JSON(ByVal JSON_DATA$, ByVal ADDR$, ByVal KEY$) As String
Try
Dim baseAddress As String = ADDR
Dim REQUEST As HttpWebRequest = CType(WebRequest.Create(New Uri(baseAddress)), HttpWebRequest)
With REQUEST
.Headers.Add("Authorization", KEY)
.Accept = "application/json"
.ContentType = "application/json"
.Method = "POST"
.ContentLength = JSON_DATA.Length
.Credentials = CredentialCache.DefaultCredentials
.KeepAlive = False
.Timeout = -1
End With
Dim parsedContent As String = JSON_DATA
Dim encoding As UTF8Encoding = New UTF8Encoding()
Dim bytes() As Byte = encoding.GetBytes(parsedContent)
Dim NewStream As Stream = REQUEST.GetRequestStream()
NewStream.Write(bytes, 0, bytes.Length)
NewStream.Close()
'Dim response As HttpWebResponse = CType(http.GetResponse(), HttpWebResponse)
Dim response As WebResponse = REQUEST.GetResponse()
Dim stream As Stream = response.GetResponseStream()
Dim sr As StreamReader = New StreamReader(stream)
Dim content As String = sr.ReadToEnd()
response.Close()
'----------------------------------------------------------------
Return response.ToString
Catch EX As WebException
MsgBox(CInt(EX.Status) & " | " & EX.Message)
End Try
Return False
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.