Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/05/2015, 23:18
wwwmaster
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: Problema al consumir web service en java

No podria garantizarlo, pero con .net yo me conecto a unos webservices asi, me retornan JSON:

Dim wbrq As HttpWebRequest = HttpWebRequest.Create(URLDELWS)
wbrq.ContentType = "application/json; charset=utf-8" '"application/x-www-form-urlencoded"

2 metodos diferentes:
wbrq.Method = "GET"
o bien:
wbrq.Method = "POST"


Adjuntando datos a la peticion:
'Get the headers associated with the request.

Dim myWebHeaderCollection As WebHeaderCollection = wbrq.Headers
myWebHeaderCollection.Add("sessionId", sessionID)
Dim RequestHttpHeaders As NameValueCollection = New NameValueCollection()

wbrq.Accept = "application/json"
wbrq.UserAgent = ".NET Framework Test Client"


LOS PARAMETROS LOS ENVIO CON UN OBJETO DICTIONARY (SOLO STRINGS x AHORA)
Dim dictionary As New Dictionary(Of String, String)
Dim PARAM1 As String = "XXXX"
Dim PARAM2 As String = "PASSWORD"
Dim PARAM3 As Long = CUSTID

dictionary.Add("username", PARAM1)
dictionary.Add("password", PARAM2)

RECUPERA RESPUESTA
Dim stream As StreamReader
Dim wbrs As HttpWebResponse = wbrq.GetResponse
stream = New StreamReader(wbrs.GetResponseStream, Encoding.GetEncoding("utf-8"))

La siguiente variable contiene la respuesta COMO STRING q luego parseo manualmente ya q por ahora no uso objetos Json en el.net

Dim JSON_respuesta As String = ""
JSON_respuesta = stream.ReadToEnd.Trim