Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Checking to see if HTTP_Get actually finds a file on the internet.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Checking to see if HTTP_Get actually finds a file on the internet.

    Ok, I am working on a method to have my app check a file on one of my domains on the internet. Then read the file and check the contents against some information in the registry.

    So, look at the file on the internet, see if the registration number in the registry matches one listed as deactivated and if so notify the user and deactivate the app so they cannot make any changes.

    I have all of that working fine but I also need to keep the app locked down if it has a deactivated registration number and they try to run it when they do not have an internet connection.

    I can do that if I also have it set a field value that depending on its value would indicate that the app has been deactivated or not.

    I also need to be able to reactivate the app by removing their registration number from the deactivated list in the file on the internet.

    So, if it can find the file on the internet, test against it. If it cannot find the file then use the field value to determine if the app is deactivated or not.

    I have tried " if .not. eval_valid("bad.body") " and that does not work.

    I have tried reading " bad.error_code " and I get a value of 0 if it can find the file or if it cannot find the file so there is no difference between the two.

    Code:
    bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
    if .not. eval_valid("bad.body")then 'This does not work
        ui_msg_box("Error","The Verification file was not downloaded from the server.",UI_STOP_SYMBOL)
    else
        dim num_regs as N
        num_regs = count_textblocks(bad.body,"<badnum>","</badnum>")
        dim item[num_regs] as P
        dim i as N
        dim this_item as C
        dim numstring as c
        dim fixed_L as C
        dim fixed_R as C
        dim bad_num as C
    
        for i = 1 to num_regs
            this_item = extract_string(bad.body,"<badnum>","</badnum>",i,.t.)
            item[i].badnum = extract_string(this_item,"<badnum>","</badnum>")
            'numstring = property_to_string(item)
            numstring = this_item
            fixed_L = ltrim(numstring,"<[1]<badnum>")
            fixed_R = Rtrim(fixed_L,"</badnum>")
            bad_num = fixed_r
            if bad_num = vc_reg_num then
            vl_deactivated = .T.	
            	'Displays a message box (style:'OK Button', image: 'Information symbol', id: 'delined_reg').
    DIM SHARED  declinedreg_result as N
    DIM SHARED  declinedreg_OK_Button as L 
    declinedreg_OK_Button = .F.
    
    title_var = "Deactivated Registration Number"
    message_text_var = <<%text%
    Your registration number has been deactivated for one or more of the following reasons.
    
    Your payment was declined or reversed.
    You requested a new number which deactivated this one.
    
    Please contact [email protected] if you feel this is in error.
    
    Registration Number: %text%+vc_reg_num
    declinedreg_result=ui_msg_box(title_var,message_text_var,UI_OK+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
    'Test to see which button on the message box was pressed....
    SELECT
    	CASE declinedreg_result = UI_OK_SELECTED
    		declinedreg_OK_Button= .t.
    END SELECT
    sys_open("http://www.shopcalsoftware.com/helpdesk/")
            end if
    next i
    'a5_show_variable(property_to_string(item)) 'Uncomment for testing
    if bad_num = "" then 'This does work if the file is not found but would also work if the file was empty.
    	ui_msg_box("Error","The Verification file was not downloaded from the server.",UI_STOP_SYMBOL)
     end if
    
    end if

    #2
    Re: Checking to see if HTTP_Get actually finds a file on the internet.

    I just ran this from the interactive window and got the following:

    Code:
    dim bad as P
    bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
    ?bad
    = body = <item>
    <cust>Jipster</cust>
    <badnum>0563-6382-2534-5784-2048</badnum>
    </item>
    <item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <item>
    <cust>My Laptop number for testing the trap</cust>
    <badnum>8765-0443-5500-4389-1038</badnum>
    </item>
    <item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <item>
    <cust>Tinhorn</cust>
    <badnum>8287-0725-8520-7389-7108</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item><cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <cust>Punk</cust>
    <badnum>8384-0790-7574-2680-7078</badnum>
    </item>
    <item>
    <cust>My Dev Machine</cust>
    <badnum>4887-5748-5796-1476-5159</badnum>
    </item>
    error_code = 0
    error_text = ""
    headers = HTTP/1.1 200 OK
    Date: Fri, 10 Jul 2015 16:01:17 GMT
    Server: Apache
    Last-Modified: Fri, 10 Jul 2015 15:54:28 GMT
    Accept-Ranges: bytes
    Content-Length: 973
    Vary: Accept-Encoding
    Connection: close
    Content-Type: text/plain
    +parsed_headers.
    I then did this and got a "positive" result

    Code:
    ?eval_valid("bad.body")
    = .T.
    I haven't done any web access from the desktop, but does this look like the results you wanted?

    Try breaking you code down into pieces and testing with the interactive window and see where it is failing.

    Tom

    Comment


      #3
      Re: Checking to see if HTTP_Get actually finds a file on the internet.

      Yes that eval_valid should work. In the interactive windows I get a .T. if the file is there and a .F. if it is not but in the actual code it does not see the true or false result on the " if .not. eval_valid("bad.body")then " statement. Maybe I need to change that to " if eval_valid("bad.body") = .F. then "

      I am working on another way to tackle this.

      If the file is there and it finds a matching registration number, set the value of a table field to True.

      The autoexec script would then read the value of that field on startup and set the value of the vl_deactivated variable that will be used to lock the app down.

      But if the script reads the matching number with an "-A" appended on the end of it then it will set the table field value to False.

      The autoexec script would then read the value of that field on startup and set the value of the vl_deactivated variable to False which would then unlock the app and allow them to use it.

      So do the test, write to a table if needed, read the table field to set the value of the vl_deactivated variable. If the " if eval_valid("bad.body") = .F. then " works then I can have it skip all the testing and just go straight to getting the value from the table.

      This way once the app is locked down when they are connected to the net then it will stay locked down, internet connection or not, until they connect to the net again and I have set their registration number to be reactivated.

      I have had a few buy my app, register it and then a few weeks later tell their CC company that they did not make the purchase an I get a charge back. I am fixing to put a stop to that. Once I get this working I will issue an update which all my customers will automatically get notified of when they start up their pc or when they start the app. Once they install the update the deactivation code will be in their app. I will then wait about a month and then add their registration numbers to the deactivate list. By waiting they will not associate the shut down with the update.

      At least that is my thinking right now.

      Comment


        #4
        Re: Checking to see if HTTP_Get actually finds a file on the internet.

        Well none of the eval_valid stuff would work in the actual code.

        But this worked
        Code:
         if extract_string(bad.body,"<badnum>","</badnum>",1,.t.) = "" then

        Comment


          #5
          Re: Checking to see if HTTP_Get actually finds a file on the internet.

          What if you split the eval out of the if?

          Code:
          Dim ans1 as L
          ans1 =  eval_valid("bad.body")then 'This does not work
          if ans1 
            code here
            else
             error code here
          end if

          Comment


            #6
            Re: Checking to see if HTTP_Get actually finds a file on the internet.

            Originally posted by Tom Henkel View Post
            What if you split the eval out of the if?

            Code:
            Dim ans1 as L
            ans1 =  eval_valid("bad.body")then 'This does not work
            if ans1 
              code here
              else
               error code here
            end if
            I will test that later. It may work.

            Here is what I have working now.

            Code:
            dim bad as P
            bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
            if extract_string(bad.body,"<badnum>","</badnum>",1,.t.) = "" then
                goto SKIP
            else
                dim num_regs as N
                num_regs = count_textblocks(bad.body,"<badnum>","</badnum>")
                dim item[num_regs] as P
                dim i as N
                dim this_item as C
                dim numstring as C
                for i = 1 to num_regs
                    this_item = extract_string(bad.body,"<badnum>","</badnum>",i,.f.)
                    item[i].badnum = extract_string(this_item,"<badnum>","</badnum>")
                    numstring = this_item
                    bad_num = numstring
                    'Check to see if the registration number has been reactivated
                    if numstring = vc_reg_num +"-A" then
                tpi = table.open("settings")
                tpi.index_primary_put("")
                tpi.fetch_first()
                WHILE .not. tpi.fetch_eof()
                    tpi.change_begin()
                    tpi.Deact = 1
                    tpi.change_end()
                    tpi.fetch_next()
                END WHILE
                tpi.close()
                    end if
                    'Check to see if the registration number has been deactivated
                    if numstring = vc_reg_num then
                tpi = table.open("settings")
                tpi.index_primary_put("")
                tpi.fetch_first()
                WHILE .not. tpi.fetch_eof()
                    tpi.change_begin()
                    tpi.Deact = 2
                    tpi.change_end()
                    tpi.fetch_next()
                END WHILE
                tpi.close()       	
                    end if
            next i
            end if
            SKIP:
            I also found by changing the .t. to .f. in the " this_item = extract_string(bad.body,"<badnum>","</badnum>",i,.f.) " statement I could do away will all the trim functions. This now just puts whatever is between the <badnum> </badnum> tags into the variable this_item.

            Comment


              #7
              Re: Checking to see if HTTP_Get actually finds a file on the internet.

              eval_valid() is meant to evaluate if an expression is valid. The URL is not an expression, thus the result of this function as such will always be false.
              Instead, if the file does not exist, the body will be empty, so instead, try:
              Code:
              bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
              if bad.body=""
              msgbox("File does not exist")
              else
              ..........
              end if
              Hopefully, this URL is a point and click or hard-coded because if the user enters the wrong URL you will get a false false result.

              Comment


                #8
                Re: Checking to see if HTTP_Get actually finds a file on the internet.

                Originally posted by G Gabriel View Post
                eval_valid() is meant to evaluate if an expression is valid. The URL is not an expression, thus the result of this function as such will always be false.
                Instead, if the file does not exist, the body will be empty, so instead, try:
                Code:
                bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
                if bad.body=""
                msgbox("File does not exist")
                else
                ..........
                end if
                Hopefully, this URL is a point and click or hard-coded because if the user enters the wrong URL you will get a false false result.
                Thanks Gabe,

                That is similar to what I came up with to get it to work.

                The url is hard coded. The user has no say in the url.

                The registration numbers I give my customers are computer specific. If they change them or try and remove them from the registry the app will shut down. The problem was that once I gave out a registration number they could use the app forever even if they had their CC company reverse the charges. Basically I have had two buy the app, register it and then in a few weeks tell their CC company they did not make the purchase and thus I ended up with a charge back and they ended up with my app for free.

                With the code I was showing here and a few other sniblets of code in the autoexec I can now shut them down. Once the app is shut down it will still start up but tells them their license has been deactivated and all they can do inside the app is look at the first screen or contact me via my support system. Only I can reactivate the app and I will not do that until I get paid.

                Anyway, the code I ended up with may not be the cleanest in the world but it works extremely well.

                If anyone needs to do something similar I would be more than happy to share what I have.

                Comment


                  #9
                  Re: Checking to see if HTTP_Get actually finds a file on the internet.

                  Originally posted by G Gabriel View Post
                  eval_valid() is meant to evaluate if an expression is valid. The URL is not an expression, thus the result of this function as such will always be false.
                  Instead, if the file does not exist, the body will be empty, so instead, try:
                  Code:
                  bad = http_get("http://www.shopcalsoftware.com/t5/notactive.txt")
                  if bad.body=""
                  msgbox("File does not exist")
                  else
                  ..........
                  end if
                  Hopefully, this URL is a point and click or hard-coded because if the user enters the wrong URL you will get a false false result.
                  I am far from an expert but Preston may want to check out HTTP_FETCH() and the status codes it can return.

                  Ray Lyons

                  Comment


                    #10
                    Re: Checking to see if HTTP_Get actually finds a file on the internet.

                    Originally posted by Raymond Lyons View Post
                    Preston may want to check out HTTP_FETCH() and the status codes it can return.
                    Ray Lyons
                    This should also work, a little more..but it should work with the same idea.

                    Comment

                    Working...
                    X