West Wind Internet and Client Tools
Problem with wwJsonServiceClient::CreatewwHttp
Gravatar is a globally recognized avatar based on your email address. Problem with wwJsonServiceClient::CreatewwHttp
  Julio Cesar Santone
  All
  Aug 10, 2017 @ 07:33pm

Hi, I'm having trouble overriding default wwHttp behavior through the method CreatewwHttp. Need to set a Header for Authentication but not seems to work

DO wwHTTP
DO wwJsonSerializer

loClient = CREATEOBJECT("wwJsonServiceClient")

loHttp = CREATEOBJECT("wwHttp")
loHttp.AddHeader("Authorization", "Basic "+STRCONV("65789:65789",13))

loClient.CreatewwHttp(loHttp)

loResourceSets = loClient.CallService("https://www.amr.org.ar/gestion/webServices/autorizador/test/convenios")

IF loClient.lError
   ? loClient.cErrorMsg
   RETURN
ENDIF
   
? loResourceSets.Count

RETURN

I debbuged it with Fiddler to check what was sent to the server and no authentication header is set

GET https://www.amr.org.ar/gestion/webServices/autorizador/test/convenios HTTP/1.1
User-Agent: West Wind Internet Protocols 6.10
Host: www.amr.org.ar
Cache-Control: no-cache

What am I doing wrong ?

Gravatar is a globally recognized avatar based on your email address. re: Problem with wwJsonServiceClient::CreatewwHttp
  Julio Cesar Santone
  Julio Cesar Santone
  Aug 10, 2017 @ 08:12pm

I think that the CreatewwHttp when it's called by the CallService method overrides the custom http created before this call. I modified CreatewwHttp checking if there's a valid "ohttp" Object before create a new one

************************************************************************
*  CreatewwHttp
****************************************
***  Function: Overrides the default wwHttp instance with a preset
***            custom instance. 
***    Assume: Set before making the actual service call
***            Metho
***      Pass: loHttp   -   (optional) Preconfigured wwHttp Instance
***    Return:
************************************************************************
FUNCTION CreatewwHttp(loHttp)

IF VARTYPE(loHttp) = "O"
    this.oHttp = loHttp
ELSE
*	Check added to original code	
	IF VARTYPE(this.oHttp) # "O"
		this.oHttp = CREATEOBJECT("wwHttp")
	ENDIF	
ENDIF	

RETURN this.oHttp
ENDFUNC
*   CreatewwHttp

Gravatar is a globally recognized avatar based on your email address. re: Problem with wwJsonServiceClient::CreatewwHttp
  Rick Strahl
  Julio Cesar Santone
  Aug 11, 2017 @ 10:26am

Hmmm... yes I guess that's correct 😃

Originally the idea was that the HTTP object needs to be re-created for each request but you should definitely be able to set the object prior to calling methods.

Fixed on this end.

Thanks,

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Problem with wwJsonServiceClient::CreatewwHttp
  Julio Cesar Santone
  Rick Strahl
  Aug 11, 2017 @ 10:58am

Thanks to you Rick.

Regards

© 1996-2024