Ayuda con crear un JSon, no funciona

Ayuda con crear un JSon, no funciona

Postby noe aburto » Wed Aug 15, 2018 4:45 pm

Saludos.

Siguiendo algunos ejemplos de miembros del foro, quiero crear un archivo json, para enviar informacion a un webservice, pero no me funciona, aparente se va la informacion pero no me reposnde nada:

mi codigo:

Code: Select all  Expand view

#include "fivewin.ch"

Function APIS(cOpe)
local doc,oHttp,cText,cText1,response,cStr,hHash,nLen,r

default cOpe:='VU'

doc:=CreateObject( "MSXML2.DOMDocument" )
oHttp:=CreateObject( "MSXML2.XMLHTTP" )
if cOpe=='VU'
 oHttp:Open( "POST" ,"http://www.answerspip.com:80/apidms/v1/Venta",.F.)
endif
oHttp:SetRequestHeader("cache-control", "no-cache")
oHttp:SetRequestHeader("content-type",  "application/json" )
oHttp:SetRequestHeader("authorization", "Token token=398336e2a7bbeaac6d3858c1551a8536" )
if cOpe=='VU'
 cText:=MemoRead("p:\tmp\ventauni.json")
endif
TRY
 oHttp:Send( cText )
 ? cText
CATCH                                                                                                                              
 msginfo("No Se Pudo Enviar Documento JSON","Intente Nuevamente")
 return .t.
END
response:=oHttp:responseText
if cOpe=='VU'
 MemoWrit( 'p:\tmp\SendVentaUni_Res.json',response)
 cText1:=MEMOREAD("p:\tmp\SendVentaUni_Res.json")
endif
?cText1 // ver respuesta del servidor .
return NIL
 


y el contenido del archico p:\tmp\ventuni.json es:
*************************************************************
{
"invoice": {
"IdMarca": "010",
"IdDistribuidor": "497",
"IdInterfaz": "MX00000088",
"IdEjecutivo": "090",
"IdCliente": "48045",
"Apellido_Paterno": "GUTIERREZ",
"Apellido_Materno": "TREJO",
"Nombre": "ALDO ISMAEL",
"Telefono1": "5552928000",
"Telefono2": "0445552928000",
"Email": "naburtos@gmail.com",
"TipoPersona": "0",
"TipoVenta":" "AUTOFINANCIAMIENTO",
"No_Factura": "003957",
"Clave_Modelo": "J1L",
"Clave_Color": "AEM",
"Clave_Color_Int": "TCG",
"Fecha_Factura": "20170724",
"Fecha_Entrega": "20180730",
"No_Vin": "8AFWR5DV6H6497124",
"Numero_Inventario": "2852-17",
"RazonComercial": "",
"IdProspectoSicop": "48045",
"Calle": "AVENIDA PLAZA DEL SOL",
"No_Ext": "25",
"No_Int": "41",
"Colonia": "RINCONADA DEL SOL",
"Delegacion_Municipio": "ZAPOPAN",
"Estado": "JALISCO",
"CP": "45055",
"RFC": "GUTA880104RA4",
"Matricula": "1234-XXX",
"Fecha_Matricula": "",
"Descripcion_Auto": "RANGER XLT CREW",
"Descripcion_Version": "",
"Descripcion_Color": "EX24",
"Descripcion_ColorInt": "IN19",
}
}
*************************************************************

en caso de que hubiera error deberia mandar:

msginfo("No Se Pudo Enviar Documento JSON","Intente Nuevamente")

no lo avisa, pero el: response:=oHttp:responseText
esta en blanco.

alguna sugerencia porfa.
Noé Aburto Sánchez
Tec. Prog. de Sistemas. -Morelia, Mich. México.
fwh 20.06, Harbour 3.2.0, bcc 7.4
TsBrowse 9.0, TsButton 7.0, xEdit 6.1
naburtos@gmail.com, noeaburto67@hotmail.com
User avatar
noe aburto
 
Posts: 418
Joined: Wed Nov 26, 2008 6:33 pm
Location: Morelia, Mich. Mexico.

Re: Ayuda con crear un JSon, no funciona

Postby Carlos Mora » Sun Aug 19, 2018 9:53 am

Es que es un servicio REST, si haces un POST y sale bien recibirás una respuesta vacia con el código http correspondiente ( 200 OK ó en tu caso sería mejor un 201 Created) pero la respuesta es VACIA.
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 11 guests