No announcement yet.

wininet help needed

  • Filter
  • Time
  • Show
Clear All
new posts

  • wininet help needed

    hi all
    i have been working on a program and about to give up.
    i only have one problem to solve, or at least that is what i think anyways.
    i need code with using pb tcp functions to
    open a website, send a request and receive that request.
    the request is already in a string from another source, so i do not not want to analyze the request, i just what to shoot the string to the web server and retrieve the results.

    the problems with tcp routines comes when you are using an internet connection and when trying to get the last packet sent, there is a cost in time you pay. everything is fast enough up till then but when that packet size does not equal the you size in the tcp statement, your going to have to wait till the timeout value has been hit. that is the only thing that slows down an internet connection using pb tcp routines while retrieving data(packets) of unknown lengths, other that, while using tcp with known packet lengths or just knowing when the data being sent is done, one can make the program very fast, because you do not have to depend on the timeout feature.

    i would suggest to anybody using tcp work and making use of pb tcp routines, that they send and receive all data in a preset size blocksize, and inside the packet, maybe the first byte could be a flag indicting whether it is the last packet send or not. it would be advised to also send how long the data is in that last packet too. come to think of it, it might be better to a packet with that information(the end of data has been reached and size the last data send), but there will be one more packet sent after that, where the receiving program can change the size of the packet being expected inside the tcp recv routine or the program sending can send that information on the first packet for the receiving program to read.

    thanks paul
    Last edited by Paul Purvis; 30 Mar 2008, 04:57 PM.
    p purvis

  • #2
    This is what i use Paul.

         %PBWININET_INC = 1
      LOCAL sBuffer         AS ASCIIZ * 50001
      LOCAL iResult         AS INTEGER
      LOCAL sData           AS STRING
      LOCAL hInternet       AS DWORD
      LOCAL hSession        AS DWORD
      LOCAL lReturn         AS DWORD
      LOCAL dwBufferLength  AS DWORD
      LOCAL URL             AS ASCIIZ * 5001
      LOCAL szHeader as ASCIIZ * 1024
      LOCAL lHeadLenth  as LONG
    '  Compressed reply
    '  szHeader =   "User-Agent: AGENT/" + $CRLF + _
    '               "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + $CRLF + _
    '               "Accept-Language: en-us,en;q=0.5" + $CRLF + _
    '               "Accept-Encoding: gzip,deflate" + $CRLF + _
    '               "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + $CRLF + _
    '               "Keep-Alive: 300" + $CRLF + _
    '               "Connection: keep-alive" + $CRLF + _
    '               "Cache-Control: max-age=0"
      szHeader =   "User-Agent: AGENT/" + $CRLF + _
                   "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + $CRLF + _
                   "Accept-Language: en-us,en;q=0.5" + $CRLF + _
                   "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + $CRLF + _
                   "Keep-Alive: 300" + $CRLF + _
                   "Connection: keep-alive" + $CRLF + _
                   "Cache-Control: max-age=0"
       lHeadLenth = LEN(szHeader)
       URL = TRIM$(URLStr)
       hSession = InternetOpen("AGENT_HTTP", %INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0) 
       IF hSession THEN hInternet = InternetOpenUrl(hSession, URL, szHeader, lHeadLenth, %INTERNET_FLAG_EXISTING_CONNECT, 0)
          IF hInternet THEN 
             dwBufferLength = 5000
             iResult = InternetReadFile(hInternet, BYVAL VARPTR(sBuffer), dwBufferLength, lReturn)
             sData = sBuffer
             DO WHILE lReturn > 0 AND iResult > 0
                iResult = InternetReadFile( hInternet,  BYVAL VARPTR(sBuffer), dwBufferLength, lReturn)
                sData = sData + MID$(sBuffer, 1, lReturn)
          END IF
          iResult = InternetCloseHandle(hInternet)            'clean up
          iResult = InternetCloseHandle(hsession)
          FUNCTION =  sData


    • #3
      Thanks Steve,
      that helped me out some with some problems i was having with headers and i believe i still may be having some problems with them.

      i have read that internetopenurl only supports the GET method of requesting a website.

      my program is now much faster
      but there are still some issues, graphics, and signing on the web sites.
      i did not want to use any wininet, but i learned a lot.


      here is the last run at it and on my website

      p purvis