View Full Version : Autenticação Basica para consumo WebService
Tassi
24-May-2022, 04:20 PM
Olá.
Alguém tem um exemplo de como informar usuário e senha para autenticação basica para consumo de webservice?
Obrigado.
Mike Peat
25-May-2022, 06:07 AM
Yes. Basically it is just a matter of concatenating <username> ":" <password> and base64 encoding them.
So...
Function BasicAuthCreds String sUsername String sPassword Returns String
String sCreds
Pointer pEnc
Integer iVoid
Move (Trim(sUsername) + ":" + Trim(sPassword)) to sCreds
Move (Base64Encode(AddressOf(sCreds), SizeOfString(sCreds))) to pEnc // Note: in earlier (pre DF20.0) DF versions, use Length(sCreds) rather than SizeOfString
Move (PointerToString(pEnc)) to sCreds
Move (Free(pEnc)) to iVoid
Function_Return sCreds
End_Function
Should work (untested).
Mike (sorry for replying in English! ;))
Tassi
25-May-2022, 01:15 PM
Thank you very much. really worth it.;).
No objeto baseado na classe criada, também coloquei o seguinte.
Function Base64EncodeString Global String sText Returns String
Address pBase64
String sResult
Integer iVoid
Move (Base64Encode(AddressOf(sText), Length(sText))) to pBase64
Move pBase64 to sResult
Move (Free(pBase64)) to iVoid
Function_Return sResult
End_Function
Object oWSserverFormulario1 is a cWSserverFormulario
//
// Interface:
//
// Function wsConsultar String llid_pedido Returns String
// Function wsAtualizar String llfchave String llfnumcartorio String llfnumprotocolo String llfdataprotocolo String llfusuario Returns String
//
// phoSoapClientHelper
// Setting this property will pop up a view that provides information
// about the Soap (xml) data transfer. This can be useful in debugging.
// If you use this you must make sure you USE the test view at the top
// of your program/view by adding: Use WebClientHelper.vw // oClientWSHelper
Set psPassword to "ppppppppppppp"
Set psUserName to "uuuuuuuuuuuuu"
Procedure OnPreSendSOAPRequest Handle hoSOAPXml Handle hoHttp String ByRef sHost String ByRef sFilePath
Forward Send OnPreSendSOAPRequest hoSOAPXml hoHttp (&sHost) (&sFilePath)
Boolean bOK
Get AddHeader of (phoHttp(Self)) "Authorization" ("Basic" * Base64EncodeString(psUsername(Self) + ":" + psPassword(Self))) to bOk
End_Procedure
End_Object
Mike Peat
26-May-2022, 06:56 AM
Yes, that should work as well. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.