Guest User

Publica para el Foro el guille

a guest
May 1st, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.04 KB | None | 0 0
  1.  Public Sub AccederFoto()
  2.    
  3.         Dim pedido As HttpWebRequest
  4.         Dim respuesta As HttpWebResponse = Nothing
  5.         Dim reader As StreamReader
  6.         Dim direccion As Uri = New Uri("https://www.fotositio.es/Fotos/LoginPage")
  7.         Dim byteData() As Byte
  8.         Dim postStream As Stream = Nothing
  9.  
  10.         Dim fot1, fot2, key, clave As String
  11.  
  12.        
  13.  
  14.  
  15.         ''Conectando con el sitio
  16.         pedido = DirectCast(WebRequest.Create(direccion), HttpWebRequest)
  17.  
  18.         'Especificando envio POST
  19.         pedido.Method = "POST"
  20.         pedido.ContentType = "multipart/form-data"
  21.  
  22.  
  23.         '' Datos que voy a enviar....
  24.         '' Datos de Prueba
  25.         fot1= "12200724"
  26.         fot2= Left(fot1, 2) & "." & Mid(fot1, 3, 3) & "." & Right(fot1, 3)
  27.         key = "3"
  28.         clave = "elpass"
  29.  
  30.  
  31.         Dim DatosTotales As New StringBuilder
  32.         DatosTotales.Append("fot1=" & fot1)
  33.         DatosTotales.Append("&fot1=" & fot2)
  34.         DatosTotales.Append("&key=" & key)
  35.         DatosTotales.Append("&clave=" & clave)
  36.  
  37.  
  38.  
  39.         '' Creando Arrays de los datos que se van a enviar
  40.         byteData = UTF8Encoding.UTF8.GetBytes(DatosTotales.ToString())
  41.  
  42.  
  43.         '' Enviando el contenido
  44.  
  45.         pedido.ContentLength = byteData.Length
  46.  
  47.         Try
  48.             postStream = pedido.GetRequestStream()
  49.             postStream.Write(byteData, 0, byteData.Length)
  50.  
  51.         Catch ex As Exception
  52.             MsgBox(ex.Message)
  53.  
  54.         Finally
  55.             If Not postStream Is Nothing Then postStream.Close()
  56.         End Try
  57.  
  58.  
  59.         Try
  60.             ' Obteniendo respuesta
  61.             respuesta = DirectCast(pedido.GetResponse(), HttpWebResponse)
  62.  
  63.             ' Obteniendo respuesta!!
  64.             reader = New StreamReader(respuesta.GetResponseStream())
  65.  
  66.             ' Sacando resultados
  67.             Response.Write(reader.ReadToEnd())
  68.         Catch ex As Exception
  69.             MsgBox(ex.Message)
  70.  
  71.         Finally
  72.             If Not Response Is Nothing Then Response.Close()
  73.         End Try
  74.  
  75.  
  76.  
  77.  
  78.      
  79.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment