JSON with HTTPS: post

JSON with HTTPS: post

Postby TimStone » Mon May 23, 2022 5:44 pm

Please read carefully. I will try to explain.

Currently I use the process for interacting with a website, and then decoding a response in JSON. Here is a cutdown version of the fuction:

Code: Select all  Expand view


Function PostTo360( cUrl, cData, cContentType,cAuthorization )

    Local oOle,cRet:='',uRet
    default cContentType:="application/json"
    default cAuthorization:=""
        oOle   := CreateObject( "MSXML2.XMLHTTP" )
    oOle:Open( 'GET', cUrl, .f. )
    oOle:SetRequestHeader( "Content-Type", cContentType)
    oOle:SetRequestHeader( "Authorization",cAuthorization)
    oOle:Send( cData )
    cRet := oOle:ResponseBody
   
RETURN( cRet )
 


This works perfectly with most of my vendors. cURL is the website, and once opened, I send the Parameters ( cData ). cRet contains the value which I pass as a hash to decode. There is NO PROBLEM with this, except with one vendor. They just changed their API, and although this method worked before, it is not now working. It appears it is not properly getting the cData passed.

He wants me to pass the url and data as a single string to the https:// site, and get a return value.

Code: Select all  Expand view

https://theirsite.force.com/abcompany/services/apexrest/pairTerminal?abcompanyId=0013r03102frFDOAA2&terminalId=1111&DeviceLabel=TEST123
 


Can someone provide a sample for sending the full string rather than the process we normally use ? I need to save the response to a variable.

Thank you.
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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Antonio Linares » Mon May 23, 2022 8:30 pm

Dear Tim,

Please install the "postman" utility, and do the request from it to see what you get and the errors you may get too
regards, saludos

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

Re: JSON with HTTPS: post

Postby Lailton » Mon May 23, 2022 10:31 pm

Maybe you need do an URLENCODE to cDATA, sometimes if you have some special character on it, can be the reason.

What Antonio said should help you to test and verify the result.

if still not working message me on Skype and I can help you with it.
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 153
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby TimStone » Mon May 23, 2022 11:54 pm

I am sorry, but I'm not familiar with the postman utility.

If I send the full string, it will return the right data. ( URL plus data, all in one transmission ). I can do this in a web browser. However, I need to do it in the background and simply get the reply.

However, if I use the function ( above ), and first OPEN the site, then send the GET request and send just the data, although the string includes it, apparently it does not see the first parameter, and the error reporting back is that the first parameter is required.

Is there a way to combine them all in one transmission ?
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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Antonio Linares » Tue May 24, 2022 12:09 am

Dear Tim,

This is the answer that we get in PostMan:

Error: getaddrinfo ENOTFOUND theirsite.force.com


GET https://theirsite.force.com/abcompany/s ... el=TEST123
Error: getaddrinfo ENOTFOUND theirsite.force.com
Request Headers
Authorization: Basic YWRzc3lzOnBhc3N3b3Jk
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: a82c29b4-cc27-421a-8513-62bf4466823e
Host: theirsite.force.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Request Body
regards, saludos

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

Re: JSON with HTTPS: post

Postby Antonio Linares » Tue May 24, 2022 12:13 am

Dear Tim,

> If I send the full string, it will return the right data. ( URL plus data, all in one transmission ). I can do this in a web browser

Please show us how you do this, thanks
regards, saludos

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

Re: JSON with HTTPS: post

Postby Lailton » Tue May 24, 2022 12:35 am

Same error here.

Send us an example that we can try and we can help to make it to work :)
Or send us the LINK documentation where we can see how it should be.
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 153
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 1:38 am

Antonio,

The original post in this thread show you exactly what I am doing in the first code section, and I provide the full strings sent each time.

The second code section shows you the complete string that can be implemented. If I insert that string ( but I modified the data and url a bit ) in to a web browser, it comes back with a downloaded file that contains the correct response.

The tech guy for the vendor keeps insisting that because his http statement works ( in a browser ) that it will work in code.

I am using the older method with Microsoft, but I see there is now cUrl capability with Harbour. However, I don't see documentation for it. I see examples posted by people, but if you could point me to documentation it would be very helpful ( or FW sample files ? ). Perhaps that is a better way to go than what I provided in my original post at the top of this thread.
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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Antonio Linares » Tue May 24, 2022 6:34 am

Dear Tim,

> If I insert that string ( but I modified the data and url a bit ) in to a web browser, it comes back with a downloaded file that contains the correct response

Please explain exactly how you modify it or we won't be able to help you
regards, saludos

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

Re: JSON with HTTPS: post

Postby Lailton » Tue May 24, 2022 1:32 pm

Antonio,

I think that his example ( URL is some part fake just as example ), this is why we can not reproduce the communication. :mrgreen:
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 153
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 4:59 pm

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
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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Antonio Linares » Tue May 24, 2022 5:08 pm

Dear Tim,

Please look for curl_easy_init() in these forums and you will find many examples.

> The company I am working on has an NDA in place, so I modified the webaddress, and the user ID in the example

You should have said this since the beginning and not making us loose time trying something that did not work, meanwhile you said that it was properly working.
regards, saludos

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

Re: JSON with HTTPS: post

Postby TimStone » Tue May 24, 2022 5:46 pm

Antonio,

We apparently have a communication problem.

1). I said that originally I had everything working fine.
2). THEN, the company changed the API and the server
3). That is when the method I have used with all XML and JSON commuinications stopped working on this one company
4). I. DID NOT ask people to test this.
5). I said that the company rep was sending an HTTP:// request and getting a response. He apparently did this with a web browser.
6). My original question was, can we send that one line code within a program. It is the SECOND code example I provided.

Your response was to tell me to use a program that I am not familiar with. I asked for more information on it, and you did not provide a response to that question.

I won't argue with you. I looked at the threads before I asked the question about cURL. I may be "out of touch" but I still find documentation helpful, and threads on a forum are specific to one person's implementation questions and do not document a function or class.

As for wasting time, when the vendor made changes to their system, it has wasted days of my time. A bit of help would have been appreciated.

OH, and I did the search and get this response for curl_easy_init():
No posts were found because the word init| is not contained in any post.
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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: JSON with HTTPS: post

Postby Carles » Tue May 24, 2022 6:30 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: 1137
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: JSON with HTTPS: post

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

I have been spending this time reviewing posts on cURL and curl_easy ( hbcurl ).

I have the latest FWH and Harbour ( Microsoft ) with the .libs mentioned.d

What I do not have is hbcurl.ch

Does anyone have a link where I can download it ? It is NOT included in my recent Harbour downloads ( 32 and 64 bit ).

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: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 88 guests

cron