No announcement yet.

TCP Fail

  • Filter
  • Time
  • Show
Clear All
new posts

  • TCP Fail

    All of a sudden, this code which I've used for years, has suddenly starting returning this message:

    "Your browser sent a request that this server could not understand."

    It happens on multiple PCs. I used the code in other apps and get the same result.

    Any ideas why?

    'Compilable Example:  (Jose Includes)
    #Compile Exe
    #Dim All
    #Include ""
    Global hDlg As Dword
    Function PBMain() As Long
       Local app$, LocalFilePath$, URLSite$, URLVerPath$,buffer$
       'server information
       URLSite$ = ""
       URLVerPath$ = ""  'get the new app from the server
       'read the file
       Tcp Open "HTTP" At URLSite$ As #1 TimeOut 60000
       Tcp Print #1, "GET  " + URLVerPath$ + "  HTTP/1.0"
       Tcp Print #1, ""
       Tcp Recv #1, 4096, buffer$    'this gets the Header + Body
       Tcp Close #1
       buffer$ = Remain$(buffer$, $CrLf + $CrLf)   'this returns just the body
       ? buffer$
    End Function

  • #2
    I can only connect to your site via HTTPS://.

    That will break your PB HTTP code for that site.

    Your service provider made a security improvement that ended up not improving??



    • #3
      Howdy, Dale!

      If I put "" in my browser, the site comes right up. It doesn't for you?

      In the code above, I replaced all of the HTTP with HTTPS. In that case, I don't get the error message. Instead, the TCP returns an empty buffer.

      I'm don't know enough about TCP to know what the fix might be, but I will experiment with it.


      • #4

        I've also sent off a request to my server folks, asking if they have any idea what has happened.

        It is the case that my security certificate and gotten mis-handled and they had to re-install it. Perhaps something there is at the heart of the problem.


        • #5
          No, my browser could not find Once I added HTTPS it found it. Now it automatically adds the "S" even when I enter Check if your browser is doing the same.

          The code in post 1 will not communicate with a secure site.

          There is more than changing the IP port that PB does not do.


          • #6
            Howdy, Dale!

            Ok, I'll bite. What code will communicate with a secure site?


            • #7
              Howdy, Dale!

              It's funny that I can type in a file name using http:// and see it in my browser, but cannot download it with TCP? How does that work?


              • #8
                Howdy Dale,
                Well, if I type in http://xxx and get the file, then copy the URL from the browser, then the copied URL has https:// in it. The browser makes the change when communicating/negotiating with the server?


                • #9
                  And, Dale,
                  While I'm asking, does a secure server HAVE to disallow the TCP code I show above, or it is something the server folks can set to allow?


                  • #10
                    You can write the certificate handling and encryption/decryption yourself. I'd suggest a DLL which also takes care of the TCP OPEN for you.

                    A server can do both. My guess is that someone at your ISP edited the server config with out knowing why some settings were there. (just like someone at vBulletin edited the code tag processing without understanding why anybody would want multiple spaces and CRLFs)

                    So, yeah see what the ISP says about going back to nonsecure.

                    Someone here can suggest a third party DLL if you decide to go secure.



                    • #11
                      I always suggest SocketTools. Does everything I have ever needed to do (ftp, http/https, email, dns, etc). It costs a few bucks, but I've never regretted the purchase!


                      • #12
                        Dale, thanks for the advice!


                        • #13
                          Howdy, Raymond!

                          Yep, I've purchased Socket Tools and love their work. But for a short snippet, ST is a bit of overkill, especially with the DLLs I would have to distribute with my free apps.


                          • #14
                            For HTTPS...maybe MSXML or Socket Tools (paid route). or like Dale said you can roll your own...

                            This may be a good start for the MSXML way of doing it


                            • #15
                     'found this link 7/1/2020 2:34PM CST (edited)

                              'Compilable Example: (Jose Includes)
                              #COMPILE EXE
                              #DIM ALL
                              REM #INCLUDE ""  'curious why Jose includes require this?
                              #INCLUDE "MSXML.INC"
                              FUNCTION PBMAIN() AS LONG
                               LOCAL URLVerPath AS WSTRING
                               URLVerPath = "" 'get the new app from the server
                               ? test(URLVerPath)
                              END FUNCTION
                              FUNCTION test(wsUrl AS WSTRING) AS WSTRING
                               DIM sMethod AS WSTRING
                               DIM oXml AS IServerXMLHTTPRequest2
                               SET oXml = NEWCOM "MsXml2.ServerXMLHTTP.6.0"
                               sMethod = "GET"
                               IF ISTRUE(ISOBJECT(oXml)) THEN
                               oXml.Open(sMethod, wsURL, %FALSE)
                               DO WHILE oXml.ReadyState<>4
                               SLEEP 0
                               ? "[" & STR$(oXml.ReadyState) & "]"
                               ? "error exit function":EXIT FUNCTION
                               FUNCTION= oXml.ResponseText
                               ? "Unable to get version",,FUNCNAME$
                               END IF
                              END FUNCTION
                              Last edited by Mike Doty; 1 Jul 2020, 07:01 PM.
                              How long is an idea? Write it down.


                              • #16

                                I posted examples to use WinHTTP eight years ago!

                                As the examples are old, they use http in the url. Just change it to https when needed.


                                • #17
                                  Howdy, Jose and Mike and Michael!

                                  Thanks for the example and links.

                                  But, you mean I cannot use TCP at all to access a file from a secure site?

                                  What sense is that? I can download with the URL in a browser, so why would I be blocked from accessing the file with TCP? When downloading a file does it represent a risk to the server?

                                  I need a big picture comment to understand the limitation.


                                  • #18

                                    Yes, you did, but the TCP approach has worked for over a decade. I would like to better understand why it now fails. Dale's comment about TCP not working on a secure site made me wonder why.


                                    • #19
                                      See: A brief overview of the TCP/IP model, SSL/TLS/HTTPS protocols and SSL certificates



                                      • #20

                                        Thanks! Looks to be what I was asking for. Will read it tonight.