JSON with HTTPS: post

Re: JSON with HTTPS: post

Postby Carles » Tue May 24, 2022 6:44 pm

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1139
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 8:36 pm

I linked in the libraries, but when I tried to put in init(), I now get the error message that it cannot run because libcurl-x64.dll cannot be found.

I have the FW Harbour builds for 64bit (22.03) and I use Visual Studio 2022. There are NO .dll files in harbour, and that one is also not present in the FWH builds.

Where can I get this .dll ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Marc Venken » Tue May 24, 2022 9:28 pm

Tim,

Not sure that this is what you want/need, but I use this code for using several API's. It looks very the same, but who knows ....
Maybe the msgRun is what you need ?

Code: Select all  Expand view  RUN

#include "FiveWin.ch"

Function Main()
   local oWnd, oActiveX1, oActiveX2, cTemp

   DEFINE WINDOW oWnd TITLE "FiveWin multiple ActiveX support"

   @ 5, 5 BUTTON "&API TEST"     OF oWnd SIZE 100, 40  ACTION TestAPI()

   ACTIVATE WINDOW oWnd

return nil

function TestAPI()

   local oHttp
   local cUrl  := "https://petstore.swagger.io/v2/pet/1000"
   local hDatos    := { => }
   local uResponse, cCookies, I, cLink
   local cData

   //  Data to change
   cData    := '{ "name": "Noyca", "status" : "available" }'  //  PETSTORE

   //  Other samples of links that maybe can help (more data insite the url)
   // cUrl = "https://yoursite/api/v2/products/"+alltrim(cCode)+"?search=sku&token=yourtoken"

   //  This line will read the url with data and respond with uResponse.
   MsgRun( cUrl, "READING API PAGE", { || uResponse := WebPageContents( cUrl, .t. ) } )

   XBrowser( uResponse ) FASTEDIT

   hb_JsonDecode( uResponse, @hDatos )     // -> Hash
   XBrowser( hDatos ) FASTEDIT

   cUrl  := "https://petstore.swagger.io/v2/pet/"

   oHttp := FWGetOleObject( "WINHTTP.WinHttpRequest.5.1" )

   WITH OBJECT oHttp
      :SetTimeouts(0, 60000, 30000, 120000)
      :Open( "POST", cUrl, .f. )
      :SetRequestHeader( "Accept",        "application/json" )
      :SetRequestHeader( "Content-Type",  "application/json" )
      :Send( cData )
      :WaitForResponse()
      ? :Status, :StatusText // 200 OK
   END

return nil

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1442
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: JSON with HTTPS: post

Postby Marc Venken » Tue May 24, 2022 9:36 pm

I also noticed that for some API's I had to change :

:Open( "POST", cUrl, .f. )

to

:Open( "PATCH", cUrl, .f. )
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1442
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: JSON with HTTPS: post

Postby Lailton » Tue May 24, 2022 10:24 pm

Hi Tim,

Sorry if it was rude to you was not my intention, I was only trying to say that URL is not something that we can
take and test it to help you.

by way the reply for you 2 question is:
1). Would Harbour cURL be better than the Microsoft based call in the original post on this thread ?
Based in my experience I can say YES, some windows OS the method that you are using can give you problem ( not be available the PROG ID ),
ANYWAY for long those years I have used this method and work fine so far.

Code: Select all  Expand view  RUN
function _createObject()

    local oOle

    try
        oOle := CreateObject( "msxml2.xmlhttp.6.0" )
    catch
        try
            oOle := CreateObject( "msxml2.xmlhttp" )
        catch
            try
                oOle := CreateObject( "microsoft.xmlhttp" )
            catch
                oOle := Cil
            end
        end
    end

return oOle
 


It work fine to me but if you have time curl is a good option too.


2). If the answer is yes, where can I see documenation on how to use Harbour's cURL, and is there a .prg in the Samples folder.

The source to hbcurl you can find in your harbour source:
https://github.com/harbour/core/tree/ma ... rib/hbcurl

On the same folder you have some examples how to use it.

Here an example how I use it:

Code: Select all  Expand view  RUN
function curl_test()

    local pCurl := curl_easy_init()
    local nRc, cBuffer, oError

    try

        if hb_isPointer( pCurl )

            curl_easy_setopt( pCurl, HB_CURLOPT_URL, "https://harbour.page/test" )

            //? curl_easy_setopt( pCurl, HB_CURLOPT_POST, .t. )
            //? curl_easy_setopt( pCurl, HB_CURLOPT_POSTFIELDS, hb_jsonEncode( { "user" => "demo", "pass" => "demo" } ) )

            // if need to ignore certificate
            // curl_easy_setopt( pCurl, HB_CURLOPT_SSL_VERIFYPEER, .f. )
            // curl_easy_setopt( pCurl, HB_CURLOPT_SSL_VERIFYHOST, .f. )

            if ( nRc := curl_easy_perform( pCurl, @cBuffer ) ) == 0
                ? cBuffer
            else
                cBuffer := curl_easy_strerror( nRc )
                ? "error: ", cBuffer
            endif

            curl_easy_cleanup( pCurl )

        endif

    catch oError

        ? oError:description

    end

return nil


Download and Official website CURL
https://curl.se/download.html

That's it, I hope it can help in something.

TimStone wrote:Antonio and Lallton,

I really don't believe my question deserved those last two VERY RUDE responses.

The company I am working on has an NDA in place, so I modified the webaddress, and the user ID in the example. Everything was exactly the way I am using it. Nothing is FAKE. I was not asking you to replicate the call. It is not to a public website so you could not do that.

My last question was twofold, and simple:

1). Would Harbour cURL be better than the Microsoft based call in the original post on this thread ?
2). If the answer is yes, where can I see documenation on how to use Harbour's cURL, and is there a .prg in the Samples folder.

As one who has been a part of this community since the earliest FiveWin days, and updated every year, I don't believe such disrespectful comments were necessary, and they were not appreciated.

If you can respond to the two actual questions, I would appreciate it.

Tim
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 156
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 10:25 pm

Hi Marc,

I appreciate the follow up. I wanted to work with the hbcurl.lib but it requires libcurl-x64.dll and I can't find it .... at least not in my FW and Harbour distributions, or anywhere else on my computer.

When you do the last part of your test, you ? status, but what do you use for seeing the values returned ? Also, you use POST, but my effort is a GET.

I had reviewed your thread on this previously. The MsgRun( ) is closest to what I need to accomplish because they prefer everything to be sent in a single submission ( your "Other" line ). How does that actually work ?

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Lailton » Tue May 24, 2022 10:33 pm

It is what I use with MSVC64 no sure if is compatible but you can try.

https://drive.google.com/file/d/13fkv2M ... sp=sharing

Regards,
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 156
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 10:36 pm

Llalton,

As I shared, I was not expecting testing. That's why "fake" was not received well. I had to honor my NDA agreement with vendor, so I couldn't provide the actual website and my ID.

As I tried to make clear, it is their NEW API and their NEW server that is giving me the problem. In the standard call, I can open the server, but my Send( oData ) is not seeing it on their end. I think that is because they want the whole string sent ( URL + Data ). This change came after I spent weeks communicating with them, building the integration to their product that they wanted, having it ALL fully functional, and then having them suddenly tell me they want me to use a new API and Server .... so the frustration is very real here.

I think the curl_easy is a good way to go because it appears it will accomodate what they want. Because I subscribe and have the latest Harbour and FW builds from FiveTech, I do have the libcurl.lib and hbcurl.lib. I am working with the 64 bit version, and when I try to do an init() I get the error that it can't find libcurl-x64.dll. So right now, that is my need. I need to find that particular file, compatible with Visual Studio build ( and I use VS 2022 ). I think I've gathered enough knowledge today to start working with it once I can get that .dll.

I'm sure your samples ( which I will put in my notes ) will be helpful.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 10:38 pm

It appears under shared files, there is only the 32 bit libcurl.dll
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Lailton » Tue May 24, 2022 10:41 pm

Hi Tim, I totally understand.
It is 64bits. I sent you an invite on Skype in case you need something message me and I can try to help you.

Regards,
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 156
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby Antonio Linares » Wed May 25, 2022 11:02 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: JSON with HTTPS: post

Postby TimStone » Wed May 25, 2022 5:07 pm

Thank you for the files. I now get a successful build with init() set ...

I can now start working with curl-easy- and see if I can get what I want. I believe I can based on the threads I have read so far. I appreciate the offer of online help, but at this point, trial and error will help me understand the capabilities, and allow me to use the options more broadly.

I will update this thread as I move further into the process.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post. RESOLVED

Postby TimStone » Fri May 27, 2022 9:35 pm

I want to thank the contributors to this thread.

I have now modified my code to use curl_easy capability and it is working well.
This will also allow me to expand some other capabilities within this program.

I asked questions so I would understand what I am doing, and the responses helped. I would love to see documentation for the full use of this capability, but I realize no one documents any longer except to maybe publish notes about changes.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Lailton » Sat May 28, 2022 1:05 am

Excellent Tim

It is a nice documentation about libcurl ( maybe can help )
https://everything.curl.dev/libcurl

8)
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 156
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 32 guests