Announcement

Collapse
No announcement yet.

TCP Fail

Collapse
X
 
  • 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?

    Code:
    'Compilable Example:  (Jose Includes)
    #Compile Exe
    #Dim All
    %Unicode=1
    #Include "Win32API.inc"
    Global hDlg As Dword
    
    Function PBMain() As Long
       Local app$, LocalFilePath$, URLSite$, URLVerPath$,buffer$
       'server information
       URLSite$ = "www.garybeene.com"
       URLVerPath$ = "http://www.garybeene.com/files/gbsnippets.ver"  '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??

    Cheers,
    Dale

    Comment


    • #3
      Howdy, Dale!

      If I put "http://www.garybeene.com" 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.

      Comment


      • #4
        Dale,

        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.

        Comment


        • #5
          No, my browser could not find http://www.garybeene.com Once I added HTTPS it found it. Now it automatically adds the "S" even when I enter http://www.garybeene.com 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.
          Dale

          Comment


          • #6
            Howdy, Dale!

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

            Comment


            • #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?

              Comment


              • #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?

                Comment


                • #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?

                  Comment


                  • #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.

                    Cheers,
                    Dale

                    Comment


                    • #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!

                      Comment


                      • #12
                        Dale, thanks for the advice!

                        Comment


                        • #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.

                          Comment


                          • #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 https://forum.powerbasic.com/forum/u...501#post582501

                            Comment


                            • #15
                              https://forum.powerbasic.com/forum/u...https-with-tcp 'found this link 7/1/2020 2:34PM CST (edited)

                              Code:
                              'Compilable Example: (Jose Includes)
                              #COMPILE EXE
                              #DIM ALL
                              %Unicode=1
                              REM #INCLUDE "Win32API.inc"  'curious why Jose includes require this?
                              #INCLUDE "MSXML.INC"
                              
                              FUNCTION PBMAIN() AS LONG
                               LOCAL URLVerPath AS WSTRING
                               URLVerPath = "https://www.garybeene.com/files/gbsnippets.ver" '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)
                               oXml.Send()
                               DO WHILE oXml.ReadyState<>4
                               SLEEP 0
                               ? "[" & STR$(oXml.ReadyState) & "]"
                               ? "error exit function":EXIT FUNCTION
                               LOOP
                               FUNCTION= oXml.ResponseText
                               ELSE
                               ? "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.

                              Comment


                              • #16
                                @Gary,

                                I posted examples to use WinHTTP eight years ago!
                                See: https://forum.powerbasic.com/forum/j...p-com-examples

                                As the examples are old, they use http in the url. Just change it to https when needed.
                                Forum: http://www.jose.it-berater.org/smfforum/index.php

                                Comment


                                • #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.


                                  Comment


                                  • #18
                                    Jose!

                                    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.

                                    Comment


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

                                      https://medium.com/jspoint/a-brief-o...s-d5a6269fe29e
                                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                                      Comment


                                      • #20
                                        Jose,

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

                                        Comment

                                        Working...
                                        X