Hello,
I'm working on converting from php to harbor,
i.e. by sending token via REST API.
After I compiled the PRG file, the results did not come out and stopped at the message "test out-1",
even though in the PHP script it worked.
Can anyone help me to get output for the PRG above ?
thanks
regards
Oksa
PHP ============================================
<?php
//2021-10-14 works!!
$personalToken = "f9v9wwFnusSWbAdt7Yivg58BDeCKm76s";
$url = "https://api.envato.com/v1/market/user:OksaSaja.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$personalToken));
$response = @curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch) > 0) {
throw new Exception("Failed to connect: " . curl_error($ch));
}
switch ($responseCode) {
case 403: throw new Exception("The personal token is missing the required permission for this script");
case 401: throw new Exception("The personal token is invalid or has been deleted");
}
if ($responseCode !== 200) {
throw new Exception("Got status {$responseCode}, try again shortly");
}
print_r($response);
$body = @json_decode($response);
if ($body === false && json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("Error parsing response, try again");
}
print_r($body);
PRG======================================================
#include "hmg.ch"
Function main
Local cAuth := "f9v9wwFnusSWbAdt7Yivg58BDeCKm76s"
Local cUrl := "https://api.envato.com/v1/market/user:OksaSaja.json"
Local nTimeOut := 20 // seconds
Local oRestApi
Local cReturn, cResponse
oRestApi := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
oRestApi:setTimeouts(nTimeout * 1000 /* nResolve */ , nTimeout * 1000 /* nConnect*/ , nTimeout * 1000 /* nSend */, nTimeout * 1000 /* nReceive */ )
If Empty( oRestApi )
? "Error al inicializar..."
Return NIL
Endif
BEGIN SEQUENCE WITH { |o| Break(o) }
oRestApi:Open( "POST", cUrl, .F. )
oRestApi:setRequestHeader( "Content-Type", "application/json" )
oRestApi:setRequestHeader( "Accept", "application/json" )
oRestApi:setRequestHeader( "Authorization: Bearer ", cAuth ) // <<--- maybe error here...
MSGINFO('test out-1')
oRestApi:Send( '' ) // <<--- error here...
MSGINFO('test out-2')
? cReturn := hb_jsonDecode( oRestApi:ResponseText() )
? hb_jsonDecode( oRestApi:ResponseBody() )
RECOVER USING oErr
MSGINFO('test out-3')
cReturn := "Error!" + hb_eol() + If ( ValType( oErr ) = 'O', oErr:Description, oErr )
END SEQUENCE
oRestApi := NIL
Return
=================================================
oErr it is an error object.
The PRG file does not fail at compille, but produces no output. Whereas for the example PHP file it can produce output.
regards
oksa
I mean, you define o and call oErr.
Dan
I mean, you define o and call oErr.
Dan
u can use script
RECOVER
MsgStop("ERROR! ")
RETURN
END SEQUENCE
i don't understand about oErr but i want my PRG run very well like my PHP script.
what is your suggestion?
regards
Oksa
I mean, you define o and call oErr.
Dan
https://www.access-programmers.co.uk/forums/threads/createobject-msxml2-serverxmlhttp-not-working.312768/
Why not to use curl?
Dan
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 251 |
Nodes: | 16 (0 / 16) |
Uptime: | 37:14:08 |
Calls: | 5,571 |
Calls today: | 1 |
Files: | 11,685 |
Messages: | 5,129,785 |