Tema: HttpRequest
Ver Mensaje Individual
  #5
Antiguo 2 de noviembre de 2021, 15:52
fastpho
El Foro es mi casa
Innovación: Por aportar innovaciones - Issue reason: SQLite + OO Cobol class Concurso: Primer puesto: Ganador/a del Primer puesto en un concurso - Issue reason: Acceso a datos Cobol vía web 
Última Actividad 21.08.2026 18:08
Posts Posts: 365
Likes enviados Enviados: 252
Likes recibidos Recibidos: 243

Citación del post de Fito Ver Mensaje
Código COBOL:
  1.  WORKING-STORAGE SECTION.
  2.  01  wsend.
  3.      02       pic x(115) value '{"000001":{"k":"1","rk":"1","b":"0","d":"CREMOSO LA LACTEO","i":"","n":"CREMOSO LA LACTEO","ld":"CREMOSO LA LACTEO"'.
  4.      02       pic x(115) value ',"nc":"0","fa":"0","dum":"UN","v":{"a":"21","f":false},"um":{"UN":{"e":"1","k":"UN","n":"UNIDAD"}}}}'.
  5.  
  6.  PROCEDURE       DIVISION.
  7.  
  8.  #include "copys\declara-com.cpy".
  9.  
  10.  comienzo.
  11.      invoke COM "CREATE-OBJECT" using winhttp returning oWS.
  12.  
  13.      invoke oWS "OPEN" using metodo arti-alta modo.
  14.  
  15.      move "Authorization"         to RH1.
  16.      move credenciales            to RH2.
  17.      invoke oWS "setRequestHeader" using RH1 RH2.
  18.  
  19.      invoke grdLista "AddItem" using credenciales.
  20.  
  21.      move "Content-Type"          to RH1.
  22.      move "application/json"      to RH2.
  23.      invoke oWS "setRequestHeader" using RH1 RH2.
  24.  
  25.      invoke oWS "send" using wsend.
  26.      
  27.      invoke oWS "get-Responsetext" returning respuesta.
  28.  
  29.      set oWS           to null.
  30.  
  31.      invoke grdLista "AddItem" using respuesta.
  32.  
  33.      exit program.
Acá trato de enviar el json de artículos. En esta prueba que les muestro el json lo cargo en una variable, pero la idea es poder enviar el archivo.

Si lo hago con Postman no tengo problemas, pero no sé traducir al cobol eso

Ahí les paso la imagen de pantalla del Postman.
En el body, selecciono binary y me pide el archivo. Ahora cómo hacerlo en Cobol no pude...

Saludos

Fito...
Podrias probar algo como esto directamente codigo no probado

Código VB:
  1. string
  2.                            '   Sub FuncionEnviarArticulo()                                      ' vbCRLF
  3.                           '        Dim RespEstado  , respuesta , success                       ' vbCRLF  
  4.                           '        Dim wsend , metodo arti-alta modo                           ' vbCRLF  
  5.                            '        Dim RH1 , RH2                                               ' vbCRLF                           
  6.  
  7.                            '        set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1") ' vbCRLF
  8.  
  9.                            '                                                                    ' vbCRLF
  10.  
  11.                            '     WinHttpReq.Open "POST", "metodo & arti-alta ",modo)             ' vbCRLF
  12.                           '                                                                    ' vbCRLF                          
  13.                           '        RH1 =   "Authorization"                                     ' vbCRLF                          
  14.                            '        RH2 =   "credenciales"                                      ' vbCRLF                          
  15.                            
  16.                            '     WinHttpReq.setRequestHeader ( RH1 , RH2 )                      ' vbCRLF                           
  17.  
  18.                            '        RH1 =   "Content-Type"                                      ' vbCRLF                          
  19.                            '        RH2 =   "application/json"                                  ' vbCRLF                          
  20.                            
  21.                            '     WinHttpReq.setRequestHeader ( RH1 , RH2 )                      ' vbCRLF                           
  22.                          
  23.                            '         set json = CreateObject("Chilkat_9_5_0.JsonObject")        ' vbCRLF
  24.                           '         success = json.LoadFile("plu.txt")                         ' vbCRLF * archivo con formato json ya creado  
  25.                           '         wsend = json.emit                                          ' vbCRLF *> variable con el registro json  
  26. *                          '         msgbox success                                             ' vbCRLF *> 1 correcto 0 error
  27.  
  28.  
  29.                            '     WinHttpReq.Send(wsend)                                         ' vbCRLF  *> envia los bloques      
  30.  
  31.                            '     WinHttpReq.WaitForResponse()                                   ' vbCRLF
  32.  
  33.                            '     respuesta = WinHttpReq.ResponseText                             ' vbCRLF
  34.  
  35.                            '          msgbox respuesta                                           ' vbCRLF
  36.                          
  37.                            '         RespEstado =  WinHttpReq.Status                            ' vbCRLF
  38.                          
  39.                            '         Estado   =  RespEstado                                     ' vbCRLF *> estado transferencia de bloques
  40.                          
  41.                            
  42.  
  43.                            
  44.                            '   End Sub                                                          ' vbCRLF                  
  45.                     delimited by size into scriptCode1
  46.                      end string
  47.       INVOKE scriptControl1 "Reset".
  48.      
  49.       invoke scriptControl1 "AddCode" using scriptCode.
  50.  
  51.       invoke scriptControl1 "ExecuteStatement" using "FuncionEnviarArticulo".
fastpho is offline   Responder Con Cita