Proxy problems - please help

K

Keith-Earl

I wrote a simple web service a year ago that runs on the clean side of our
firewall. It posts to remote Internet server which sends an alpha page to
my pager. Pretty dandy until last week. It broke, my connection was
refused, not by the remote server but by the ISA proxy.

I read every newsgroup and KB article I could find. Most suggested
modifying the machine.config or web.config file which I did. I also tried
to log into the proxy in code. Once I changed the machine.config file I did
get further (see below).

What am I doing wrong? This code worked reliably for a year.

Thanks,

Keith


<WebMethod()> _
Public Function SendPageProxy(ByVal strPagerID As String, ByVal strMsg
As String) As String

Try

'assign the proxy
Dim myProxy As New
WebProxy("http://www-proxy.thedomain.com:8080", True)
myProxy.Credentials = New NetworkCredential("User", "Pass",
"Domain")

strMsg = strMsg.Substring(0, x)

'Build HttpWebRequest, assign to pager web page
Dim lcUrl As String = "http://thedomain.com/target/send150.pl"
Dim wReq As HttpWebRequest = WebRequest.Create(lcUrl)

'Build POST data
Dim strPostData As String = "host=" +
HttpUtility.UrlEncode("192.168.1.5") & "&pagerid=" +
HttpUtility.UrlEncode(strPagerID) & "&msg=" + HttpUtility.UrlEncode(strMsg)
& "&submit.x=" + HttpUtility.UrlEncode("18") & "&submit.y=" +
HttpUtility.UrlEncode("18")
wReq.Method = "POST"
wReq.ContentType = "application/x-www-form-urlencoded"

'Get length of POST data, set in Request
Dim bytePostBuffer As Byte() =
System.Text.Encoding.GetEncoding(1252).GetBytes(strPostData)
wReq.ContentLength = bytePostBuffer.Length

'Write out the Post data
===>works Dim streamPostData As Stream = wReq.GetRequestStream() '<===
THIS STATEMENT used to BOMB before I changed the machine.config
streamPostData.Write(bytePostBuffer, 0, bytePostBuffer.Length)

streamPostData.Close()

Dim wRes As HttpWebResponse
===>bombs wRes = wReq.GetResponse() '<=== THIS STATEMENT BOMBS

Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
Dim srResponseStream As StreamReader = New
StreamReader(wRes.GetResponseStream(), enc)
Dim strHtml As String = srResponseStream.ReadToEnd()

wRes.Close()
srResponseStream.Close()

'if the ResponseStream contains the word "successfully" assume
it was successful
If InStr(strHtml, "successfully", CompareMethod.Text) Then
Return "Successful"
Else
Return strHtml
End If


Catch ex As Exception
Return ex.Message()
Finally

End Try
End Function

machine.config change

<defaultProxy>

<!-- KAR 10-Dec-03 -->
<proxy usesystemdefault="false"
proxyaddress="http://www-proxy.thedomain.com:8080"
bypassonlocal="true" />
 
D

Dino Chiesa [Microsoft]

The reason it is failing is probably because your network config changed,
without your knowledge.

To get this to work, I believe you should be attaching the proxy to the
WebRequest, before writing the POST data.

wReq.Proxy= myProxy ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top