Internet request timeout and proxy error

aidygus

New member
Joined
Nov 7, 2006
Messages
1
Ive written a bunch of applications that post and recieve information to php scripts sited on an apache server.

On some computers Ive noticed a dificulty in connecting and recieving any replies back from the php pages.

Ive used both the following methods and am getting the same result on both of them :-

Code:
        Dim res As String
        Dim myWebClient As New WebClient

        myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        res = System.Text.Encoding.ASCII.GetString(myWebClient.UploadData(URL, GetFunction, System.Text.Encoding.ASCII.GetBytes(DataString)))

        Return res

Code:
            Dim Res As String
            Dim MyWebRequest As HttpWebRequest
            Dim MyWebResponse As HttpWebResponse
            Dim encoding As New System.Text.ASCIIEncoding
            Dim postData As String
            Dim data() As Byte
            Dim sr As StreamReader
            Dim sw As StreamWriter

            data = encoding.GetBytes(DataString)

            MyWebRequest = WebRequest.Create(URL)

            MyWebRequest.Method = GetFunction
            MyWebRequest.ContentType = "application/x-www-form-urlencoded"
            MyWebRequest.ContentLength = data.Length
            MyWebRequest.Timeout = 1000
            Dim myStream As Stream = MyWebRequest.GetRequestStream()
            myStream.Write(data, 0, data.Length)
            myStream.Close()
            MyWebResponse = MyWebRequest.GetResponse
            sr = New StreamReader(MyWebResponse.GetResponseStream)
            Res = sr.ReadToEnd
            Return Res

With the webclient method the app hangs for around 30 seconds then gives a webexceprion error.

The httpwebResponse method gets as far as Dim myStream As Stream = MyWebRequest.GetRequestStream() and then gives a timeout error. Ive tried increasing the timeout to 180 seconds but I get the same result.

Now I know this is not a connection issue as I can access test php scripts from the same server which display the information that Im pulling back from them.


Ive even tried putting a proxy into the code

Code:
            WebRequest = WebRequest.Create(URL)

            If ProxyEnabled = "Y" Then
                Dim proxy As New WebProxy("http://" & ProxyServer & ":" & ProxyPort & "/", True)
                If ProxyAuth = "Y" Then
                    proxy.Credentials = New NetworkCredential(ProxyUser, ProxyPass, ProxyDomain)
                End If
                WebRequest.Proxy = proxy
            End If

            WebRequest.Method = GetFunction  "POST"

But I get a "Specified cast is not valid" error at the same point I get the timeout.

does anyone know what causes this code to not work on some computers and how to get around it?
 
Back
Top