none
Enviar datos GET a API en VB.NET con JSON LOGIN RRS feed

  • Pregunta

  • Hola,

    Me aparece este error:

    An unhandled exception of type 'System.Net.ProtocolViolationException' occurred in System.dll
    
    Additional information: No se puede enviar contenido textual con este tipo de verbo.

    Mi Codigo es:

            Dim request As HttpWebRequest
            Dim response As HttpWebResponse = Nothing
            Dim reader As StreamReader
            Dim address As Uri
            Dim dataSend As String
    
            Dim data As StringBuilder
            Dim byteData() As Byte
            Dim postStream As Stream = Nothing
    
    
            address = New Uri("http://URL")
    
            ' CREA EL REQUEST WEB
            request = DirectCast(WebRequest.Create(address), HttpWebRequest)
    
            ' SETEA A POST  
            request.Method = "GET"
            'request.ContentType = "application/x-www-form-urlencoded"
            'request.ContentType = "text/xml"
            request.ContentType = "application/json"
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE)"
            ' Create the data we want to send  
    
            data = New StringBuilder()
            data.Append("{""username"":""myuser"",""password"":""mypass""}")
            dataSend = "{""username"":""myuser"",""password"":""mypass""}"
    
            ' Create a byte array of the data we want to send  
            byteData = UTF8Encoding.UTF8.GetBytes(dataSend)
    
            ' Set the content length in the request headers  
            request.ContentLength = byteData.Length
    
            ' Write data  
            Try
                postStream = request.GetRequestStream()
                postStream.Write(byteData, 0, byteData.Length)
            Finally
                If Not postStream Is Nothing Then postStream.Close()
            End Try
    
            Try
                ' Get response  
    
                response = DirectCast(request.GetResponse(), HttpWebResponse)
    
                ' Get the response stream into a reader  
                reader = New StreamReader(response.GetResponseStream())
    
                ' Console application output  
                MsgBox(reader.ReadToEnd())
                Console.WriteLine(reader.ReadToEnd())
            Finally
                If Not response Is Nothing Then response.Close()
            End Try

    Basicamente quiero obtener la info del inicio de sesion de mi API en otras plataformas como java o as3 no tuve problemas. pero aca me aparece ese error, Es un TIPO GET y le necesito pasar los parametros para iniciar sesion user y password





    • Editado XDitel domingo, 23 de agosto de 2015 15:36 nuevo problema
    • Cambiado Enrique M. Montejo lunes, 31 de agosto de 2015 6:03 Desarrollo web
    domingo, 23 de agosto de 2015 4:14

Todas las respuestas