Call Slack API in vb.NET with proxy server

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.

+5
source share
1 answer

It may be wrong, but I'm sure the address for your proxy is incorrect. You need to pass the port separately, like Int, to the address URL. i.e.

  Dim proxyObject As New WebProxy("http://thisismyproxy", thisismyport) 

Where thisismyport is the Int value for the desired port number.

See: https://msdn.microsoft.com/en-us/library/xfsh37cx(v=vs.110).aspx

Based on your comment, I would suggest that the URL you provide for your proxy is also:

a) wrong, or ...

b) cannot be resolved using DNS

To fix, make sure that the URL http: // thisismyproxy "is 100% right - also try entering the IP address of the proxy server and not the domain name. For example.

 Dim proxyObject As New WebProxy("http://192.168.xx", 8080) 

Is this a solution to the problem? If you can not reach (ping), etc. Proxies from the computer - that is - can you even enable thisismyproxy?

0
source

Source: https://habr.com/ru/post/1275307/


All Articles