IMPORT com IMPORT os IMPORT util IMPORT security IMPORT XML DEFINE url, files STRING MAIN CALL enviaxml() # CALL pruebaget() END MAIN FUNCTION enviaxml() DEFINE arc_sal STRING, rep_out RECORD contenido STRING, nomb_arch STRING, cod_msg INT, mensaje_out STRING END RECORD, s,res STRING, rcode int LET url="https://nace.access.ly/gas/ws/r/130282722/fe/recepcion/api/ecf" # LET url="https://nace.access.ly/gas/ws/r/fe/recepcion/api/ecf" #LET url="https://ws.marmotech.com.do/gas/ws/r/101048107/fe/recepcion/api/ecf" LET arc_sal = '101521262E310000000735.xml' #LET arc_sal = 'prueba.txt' CALL enviafiles(arc_sal ) RETURNING rcode,res DISPLAY "resp: ", rcode," ",res {IF os.Path.exists(arc_sal) THEN CALL file_to_b64(arc_sal) RETURNING rep_out.contenido LET rep_out.nomb_arch=os.path.basename(arc_sal) DISPLAY "GRW file '",rep_out.nomb_arch,"' sent." LET rep_out.mensaje_out = "ADICION EXITOSA" LET s = util.JSON.stringify(rep_out) CALL enviafiles(arc_sal ) RETURNING rcode,res ELSE DISPLAY "NO ENCONTRE FILE" END IF} END FUNCTION FUNCTION pruebaget() DEFINE http_req com.HttpRequest, http_resp com.HTTPResponse, rcode,msg string LET url="https://nace.access.ly/gas/ws/r/101048107/fe/info" LET http_req = com.HTTPRequest.Create(url) CALL http_req.setMethod("GET") CALL http_req.setCharset("UTF-8") CALL http_req.doRequest() LET http_resp = http_req.getResponse() LET rcode = http_resp.getStatusCode() LET msg = http_resp.getTextResponse() DISPLAY "COD ",rcode," ",msg END FUNCTION FUNCTION enviafiles(archivo) DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING, http_req com.HttpRequest, http_resp com.HTTPResponse, doc xml.DomDocument LET btoken =" Bearer ",btoken LET http_req = com.HTTPRequest.Create(url) CALL http_req.setMethod("POST") CALL http_req.setCharset("UTF-8") CALL http_req.setHeader("accept","application/xml") # CALL http_req.setHeader("Authorization",btoken) CALL http_req.setMultipartType("form-data",NULL,NULL) # "form-data; name=\"xml\"; filename=\"naceSignature.xml\"" IF os.Path.exists(archivo) THEN LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo) CALL http_req.setHeader("Content-Disposition", contenido CLIPPED) DISPLAY "encontre el file ",archivo # CALL http_req.doFileRequest(archivo) TRY CALL http_req.doFileRequest(archivo) #LET http_resp= http_req.getResponse() # LET codigo = http_resp.getStatusCode() # LET respuesta= http_resp.getTextResponse() LET http_resp= http_req.getResponse() LET codigo = http_resp.getStatusCode() LET respuesta= http_resp.getTextResponse() CATCH LET http_resp= http_req.getResponse() LET codigo = http_resp.getStatusCode() LET respuesta= http_resp.getTextResponse() DISPLAY "error: ",codigo," ", respuesta END TRY END IF RETURN codigo, respuesta END FUNCTION FUNCTION show_sync_err(msg) DEFINE msg STRING DISPLAY "ERROR: ",msg # CALL fgl_winmessage(%"ERROR", msg, "exclamation") END FUNCTION FUNCTION file_to_b64(f_ent) DEFINE f_ent,str_b64,str_aux STRING LET str_b64=NULL TRY CALL security.Base64.LoadBinary(f_ent) RETURNING str_b64 CATCH LET str_aux="Unable to convert file into a Base64 String:",STATUS # CALL fgl_winmessage("Error",str_aux,"stop") LET str_b64=NULL END TRY RETURN str_b64 END FUNCTION