Hi all,
Could you check that code.
I'm trying to access REST web service using HTTP basic authntication, but this is not working as well.
Could you help me ?
#include "fivewin.ch"
function main()
local ohttp := CreateObject( "MSXML2.XMLHTTP" )
set date french
set century on
oHttp := CreateObject( 'Microsoft.XMLHTTP' )
cHttpSend := [{ "Username": ]+hb_base64Encode("test:")+[, "Password": ]+hb_base64Encode("12345")+[}]
cUri:="https://demosite/DiamicBiothequeService ... tientinfos"
ohttp:Open( "GET" ,cUri, .F. )
ohttp:SetRequestHeader( "Accept" , "application/json" )
ohttp:SetRequestHeader( "Content-Type" , "application/json" )
*ohttp:SetRequestHeader( "Username" , hb_base64Encode("test:"))
*ohttp:SetRequestHeader( "Password" , hb_base64Encode("12345") )
ohttp:SetRequestHeader( "Authorization" , cHttpSend )
try
ohttp:Send( cHttpSend )
catch
MsgInfo( "Connection error:" + oHttp:lastErrorMessage())
end
msgalert( alltrim(ohttp:responseText) )
return .T.
Thank you in advance.
kind regards.
Jack.
Web service HTTP GET Basic Authentication howto
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Web service HTTP GET Basic Authentication howto
hb_base64Encode() requires the length of the string as the second parameter (at least with xHarbour):
EMG
Code: Select all
hb_base64Encode("test:",5)
Re: Web service HTTP GET Basic Authentication howto
Hi,
Thank you for your answer.
I continue to search and I found a solution.
oHttp:Open( 'GET', "https://demoweb/DiamicBiothequeService. ... tientinfos", .f. )
oHttp:SetRequestHeader( "Content-Type","application/json") /* if its json*/
ohttp:SetRequestHeader( "Authorization", "Basic "+hb_base64Encode("user:pwrd"))
oHttp:Send()
This code is working but I have just one blocking step.
I receive a security alert to accept the certificate.
Is this a way to avoid this certificate alert ?
Like it is done in .Net with this code :
private static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
}
/// <summary>
/// Certificate validation callback.
/// </summary>
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
//Debug.WriteLine("Trusting X509Certificate '" + cert.Subject + "'");
return true;
}
Thank you.
Kind regards.
Jack.
Thank you for your answer.
I continue to search and I found a solution.
oHttp:Open( 'GET', "https://demoweb/DiamicBiothequeService. ... tientinfos", .f. )
oHttp:SetRequestHeader( "Content-Type","application/json") /* if its json*/
ohttp:SetRequestHeader( "Authorization", "Basic "+hb_base64Encode("user:pwrd"))
oHttp:Send()
This code is working but I have just one blocking step.
I receive a security alert to accept the certificate.
Is this a way to avoid this certificate alert ?
Like it is done in .Net with this code :
private static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
}
/// <summary>
/// Certificate validation callback.
/// </summary>
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
//Debug.WriteLine("Trusting X509Certificate '" + cert.Subject + "'");
return true;
}
Thank you.
Kind regards.
Jack.