Web service HTTP GET Basic Authentication howto
Posted: Fri Feb 10, 2017 2:50 pm
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.
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.