fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Check HTTP request for string part

    Questions & Answers
    3
    9
    2575
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sebabahn last edited by

      Hi,

      I want to use a HTTP request to check for a valid license.

      HTTP request works, when I switch on the response message I receive the output from the website correctly.

      Now I want to check, if some parts of the response are adequate.

      This is the complete response:

      Array
      (
          [api_version] => 1.020
          [current_time] => 2017-09-08 00:12:47
          [result] => success
          [data] => Array
              (
                  [is_license_valid] => Y
                  [is_license_key_found] => Y
                  [purchase_id] => ALE7KD7W
                  [license_key] => RB73P-VVRS7-W3KEH-S4WSC-8UZC3-9JDQZ-D75EQ-VZMC7
                  [billing_tatus] => completed
                  [billing_tatus_msg] => Vollständigt bezahlt
                  [last_payment_at] => 2017-09-07
                  [last_payment_at_msg] => 07.09.2017
                  [next_payment_at] => 
                  [next_payment_at_msg] => 
                  [last_transaction_type] => payment
                  [last_transaction_type_msg] => Zahlung
                  [are_returned_data_public] => N
              )
      
      )
      

      I only want to check for

      [is_license_valid] => Y
      

      If this is missing or "N", I want to stop the EA, if it is "Y" it should run as expected.

      How can I set up a condition to check this part of a string?

      Best regards,
      Sebastian

      1 Reply Last reply Reply Quote 0
      • fxDreema
        fxDreema last edited by fxDreema

        This is some PHP type of response, but MQL is very stupid, it doesn't have those complex web abilities. The response that is expected is either plain text or values separated by some delimiter 🙂

        S 1 Reply Last reply Reply Quote 0
        • S
          sebabahn @fxDreema last edited by

          @fxDreema

          This is the plain text output 😉

          Output from the website is also possible as JSON, PHP or XML.

          maybe XML is good for searching for a string, but how can I access the HTTP response in a condition (not the first condition block, but the second with code input)?

          1 Reply Last reply Reply Quote 0
          • fxDreema
            fxDreema last edited by

            MQL4 sees that answer as plain text, there is no XML, JSON or another parser. Really, the only format that I made it available to read is delimiter-separated format, something like this - value1,value2,value3 - if the Delimiter is set to comma in the HTTP block. Then, in Condition you can access value2 for example, if you set Key to be 1 (because Key is the position in the delimiter-separated string if the first position is 0).

            1 Reply Last reply Reply Quote 0
            • S
              sebabahn last edited by

              ok, can you provide me a code sample to access that value? what is the name of the response variable?

              1 Reply Last reply Reply Quote 0
              • fxDreema
                fxDreema last edited by

                What value? I told you how it works - the request is sent with a MQL4 function, then the response is turned into an array, and the data from that array is read somewhere in the Condition block. The array's name is FXD_HTTP_RESPONSE and it has at least 1 value (for key 0) or multiple values if delimiter was used. But don't use that variable name for nothing, this is some variable that I made for this situation and I may change it at any time.

                Again, JSON, XML or any other ways to represent an associative array doesn't work here. For MQL4/MQL5 your response means nothing - it's just a string that contains many letters and some [ and ] symbols, nothing special. And in fact, in MQL4/MQL5 we don't even have associative arrays. Arrays in MQL4/MQL5 can only have numeric keys, or I don't know how they can have string keys.

                1 Reply Last reply Reply Quote 0
                • S
                  sebabahn last edited by

                  Let me make this more clear.

                  I created this process:

                  0_1505772047305_Bildschirmfoto 2017-09-19 um 00.00.09.png

                  Now I want to check the HTTP response, and the condition should be true if the response CONTAINS my string. So I think I need a "contains" in the Equals list, not "==", correct? How can I implement this?

                  1 Reply Last reply Reply Quote 0
                  • S
                    sebabahn last edited by

                    Anybody an idea how to solve this?

                    C 1 Reply Last reply Reply Quote 0
                    • C
                      chicrala @sebabahn last edited by chicrala

                      @sebabahn I think that could help you. Try to find the string and get the result... https://www.mql5.com/en/docs/strings/stringfind

                      search for "[is_license_valid] =>". Something like this:

                      StringFind(
                      YOURstring, // string in which search is made
                      "[is_license_valid] =>", // what you want to find
                      0 // from what position search starts
                      );

                      ... and then you can use a StringSubstr to extract the result. Not so elegant but, considering the mql language limitations...

                      StringSubstr(
                      YOURstring, // string
                      start_pos, // position to start with from your code above (StringFind)
                      length=-1 // length of extracted string considering "[is_license_valid] =>" length
                      );

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post

                      Online Users

                      J
                      E
                      E
                      M
                      E
                      M
                      A
                      P
                      M
                      P
                      A

                      16
                      Online

                      146.8k
                      Users

                      22.4k
                      Topics

                      122.6k
                      Posts

                      Powered by NodeBB Forums | Contributors