Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've written a bunch of applications that post and recieve information to php scripts sited on an apache server.

 

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

 

I've used both the following methods and am getting the same result on both of them :-

 

        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

 

            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. I've 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 I'm pulling back from them.

 

 

I've even tried putting a proxy into the 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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...