Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: lmb10000 en Noviembre 14, 2023, 04:49:48 pm
-
Hola
Necesito subir a un endpoint informacion , metodo POST y estoy usando la libreria WintHTTP para VB6.
Construyo el JSON con los parametros documentados pero no funciona
No tengo mucha idea del lenguaje para crear el JSON pero usando la documentacion cree una cadena que invoca a la URL + el JSON .
Si alguien tiene idea de esto podria exponer parte de la documentacion del endpoint y el JSOn que genero para hacer le POST a ver si alguien me puede ayudar
Muchas gracias de antemano
Luis
-
Poner en un formulario un commandbutton
Option Explicit
'curl -X POST https://reqbin.com/echo/post/json
' -H 'Content-Type: application/json'
' -d '{"login":"my_login","password":"my_password"}'
Private Sub Command1_Click()
Dim bvData() As Byte
Dim nFile As Integer
Dim cFile As String
Dim cUrl As String
Dim cData As String
Dim i As Long
Dim c As String
cUrl = "https://reqbin.com/echo/post/json"
cData = "{[cc]login[cc]:[cc]my_login[cc],[cc]password[cc]:[cc]my_password[cc]}"
cData = Replace(cData, "[cc]", Chr(34))
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "POST", cUrl, False
.send cData
Debug.Print ("OK" = .StatusText)
nFile = FreeFile
cFile = App.Path & "\data.json"
Open cFile For Binary Access Write As #nFile
bvData() = .responsebody
Put #nFile, , bvData()
Close #nFile
c = ""
For i = 0 To UBound(bvData)
c = c & Chr(bvData(i))
Next
Debug.Print c
End With
End Sub
JsonBag Class
https://www.vbforums.com/showthread.php?738845-VB6-JsonBag-Another-JSON-Parser-Generator&highlight=jsonbag+class (https://www.vbforums.com/showthread.php?738845-VB6-JsonBag-Another-JSON-Parser-Generator&highlight=jsonbag+class)
Online REST & SOAP API Testing Tool
https://reqbin.com/ (https://reqbin.com/)
Para probar endpoint puedes usar Postman
https://www.postman.com/downloads/ (https://www.postman.com/downloads/)
-
Gracias Benito!!!
Creo que ahora funciona
Yo enviaba en el OPEN la URL + JSON y en el send nada
Envianso en el OPEN solo la URL con el metodo POST y en el SEND el JSON funciona!!!!
Un millon de gracias!!!!!!