In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Web service

Foro público de Xailer en español
Responder
cfuentes
Mensajes: 30
Registrado: Mié May 13, 2020 6:45 pm

Web service

Mensaje por cfuentes »

Buenas tardes estimados, estoy trabajando en un web service, pero al enviar el POST se esta redirigiendo a un sitio no deseado y quiero redireccionarlo, hacer un Redirect o un folowredirect a Falso y no he tenido exito. Alguien sabe como poner el Falso la option Redirect? Alguna recomendacion, por favor.

Gracias anticipadas, a continuacion el codigo utilizado:

cProducts += ']'
cBody := '{"products":' + cProducts + ','
cBody += '"external_verifications":[{"type":"NATIONAL_IDENTITY_CARD","value":"' + '' + aResponseText["patient_document_number"] + '"}], "currency_code":"DOP"}'
cWebService := "https://sandbox.osigu.com/dispensing/v1/documents/"
cWebService += ::oPreautoriza:Value + "/dispensations"
oHttp := CreateObject( "WinHTTP.WinHttpRequest.5.1" )
//oHttp := CreateObject( "MSXML2.XMLHTTP" )
oHttp:open( "POST", cWebService, .F.)
oHttp:SetRequestHeader("Accept", "application/json")
oHttp:SetRequestHeader("content-type","application/json")
oHttp:SetRequestHeader("authorization", &cToken)

oHttp:Option(6, .F.) // Aqui trato de hacer el Redirect, pero no me funciona

oHttp:send( cBody ) //Buscar como obtener la respuesta del reclamo generado, antes de consumir el location.
oHttp:WaitForResponse()
cResponseText := oHttp:getResponseHeader('Location')


Carlos Fuentes
Avatar de Usuario
gabo1
Mensajes: 127
Registrado: Lun Oct 13, 2014 9:42 am

Re: Web service

Mensaje por gabo1 »

Hola cFuentes
Este ejemplo es del Grupo de usuarios de harbour quizas te pueda ayudar, Saludos!

Código: Seleccionar todo

#include "hbcurl.ch"
#include "common.ch"
#include "fileio.ch"

FUNCTION Main( )
	LOCAL exitStatus
	LOCAL endpointUrl

	LOCAL postData
	LOCAL curlHandle
	LOCAL curlErr
	LOCAL aHeader

	  /* Exit status to return */
	exitStatus := 0
	endpointUrl = "http://wsf.cdyne.com/WeatherWS/Weather.asmx"

	// Parameters for call

	postData := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/">'
	postData += '<soapenv:Header/>'
	postData += '<soapenv:Body>'
	postData += '<weat:GetWeatherInformation/>'
	postData += '</soapenv:Body>'
	postData += '</soapenv:Envelope>'

	? postData

	aHeader := {}
	AADD(aHeader,"Accept-Encoding: gzip,deflate" )
	AADD(aHeader,"Content-Type: text/xml;charset=UTF-8" )
	AADD(aHeader,'SOAPAction: "http://ws.cdyne.com/WeatherWS/GetWeatherInformation"' )
	AADD(aHeader,"User-Agent: Jakarta Commons-HttpClient/3.1"  )

  /* Initialise libcurl */
	curl_global_init()

	/* Get a curl handle */
	curlHandle := curl_easy_init()

	IF .NOT. EMPTY(curlHandle)

		/* Specify the Header  data */
		curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,  aHeader)
		
		/* Set the endpoint to send the POST to */
		curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl);
		
		/* Specify the POST data */
		curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, postData);
		/* Execute the POST, response goes to STDOUT */

		curlErr = curl_easy_perform(curlHandle);
		/* Report any errors */

		IF .NOT. EMPTY(curlErr)
			? curl_easy_strerror(curlErr)
		ENDIF
	ELSE
		? "No handle"
	ENDIF
	IF .NOT. EMPTY(curlHandle)
		/* Clean-up libcurl */
		curl_global_cleanup()
	ELSE
		exitStatus = 1
	ENDIF
  /* Return the exit status */

RETURN exitStatus

// ESTE ES OTRO EJEMPLO

------------------------------
#include "hbcurl.ch"
#include "common.ch"
#include "fileio.ch"

function fHttpExecute(cxml)
local endpointUrl,curlHandle,curlErr
local aHeader,chpmserv,cc1

cc1 := ""

cservice := "InformationsService"
caction := "LiefereKernversion"
chpmserv := "localhost"
endpointUrl = "http://"+chpmserv+":22220/"+cservice+".asmx"

aHeader := {}
AADD(aHeader,"Accept-Encoding: gzip,deflate" )
AADD(aHeader,"Content-Type: application/soap+xml;charset=UTF-8")
AADD(aHeader,'action="http://some-website.de/'+caction+'"')
        
curlHandle := curl_easy_init()

if !empty(curlHandle)

/* Specify the Header  data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,aHeader)

/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl)

/* Setup response data */
curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )

/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POST, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cxml)

/* Do everything */
curlErr := curl_easy_perform(curlHandle)

/* Report any errors */
if empty(curlErr)
/* store response in variable */
cc1 := curl_easy_dl_buff_get( curlHandle )
else
? curl_easy_strerror(curlErr)
endif
else
? "No handle"
endif

if !empty(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup( curlHandle )
else
? "Error"
endif

if empty(cc1)
? "Error"
endif

return cc1
cfuentes
Mensajes: 30
Registrado: Mié May 13, 2020 6:45 pm

Re: Web service

Mensaje por cfuentes »

Gabo, mil gracias por la respuesta, realmente no tengo problemas con el web services, lo he trabajado en este y otros proyectos, pero nunca habia enfrentado el caso de tener que redireccionar, utilizar un Redirect. Aprendi que va de la mano con el CreateObject, pero no he logrado hacer que se ponga en Falso.

Muy agradecido por tu respuesta, me has dado luz para saber que el Forum de Harbour es una opcion, que nunca tenia en cuenta.

Gracias, un abrazo

Carlos Fuentes
Responder