Trying to call the Slack API through an application in vb.NET for a proxy. However, I have no experience in .NET, so this is somehow from my league.
This is part of the code:
Private Function GetResponseFromPostRequest(ByVal url As String, ByVal variables As String) As String Dim content As String Dim postData() As Byte = Encoding.GetEncoding("utf-8").GetBytes(variables) Dim req As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest) Dim proxyObject As New WebProxy("http://thisismyproxy:thisismyport") req.Proxy = proxyObject req.Method = "POST" req.ContentType = "application/json" req.ContentLength = postData.Length Dim postStream As Stream = req.GetRequestStream() postStream.Write(postData, 0, postData.Length) postStream.Close() Using res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) Using receiveStream As Stream = res.GetResponseStream() Dim readStream As New StreamReader(receiveStream, Encoding.GetEncoding("utf-8")) content = readStream.ReadToEnd() End Using End Using Return content End Function
Then name it like this:
GetResponseFromPostRequest("https://hooks.slack.com/services/....", "{'text':'" & slackTitle & "'}")
Without a proxy, it works. With a proxy, I have the following error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ...an api...
If I try to make an HTTP message in the mail application and use the proxy server above, it works. I think the problem should be in vb.net code.
source share