|
642
|
Programación / .NET (C#, VB.NET, ASP) / Re: Enviar un Form usando Httprequest !!
|
en: 13 Febrero 2013, 19:52 pm
|
Holas de nuevo chicos pues miren los avances y con ellos nuevas frustaciones, leyendo sobre como subir archivos encontre que el code anterior no se aplica hay que hacerle algunas correciones por lo que pongo mis modificaciones.. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'UploadLocalFile() Dim CookieJar As New CookieContainer Dim Url As String = "http://lok.myvnc.com/insertar-anuncio.html?isDBMode=1" Dim parametros As New NameValueCollection() ' Create the data we want to send parametros.Add("var1", "1235") parametros.Add("var2", "524") parametros.Add("var3", "Mas información para mandar") parametros.Add("var4", "Mas informacion para mandar") parametros.Add("var5", "jdueybd@gjhf.com") parametros.Add("var6", "123456") parametros.Add("var7", "654321") parametros.Add("var8", "Pepin") Uploaddata(CookieJar, Url, "C:\corazon.jpeg", "ad_picture_a", "image,jpeg", parametros) End Sub 'Funcion que manda la información Public Function Uploaddata(ByVal containa As CookieContainer, ByVal uri As String, ByVal filePath As String, ByVal fileParameterName As String, ByVal contentType As String, ByVal otherParameters As Specialized.NameValueCollection) As String Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString("x") Dim newLine As String = System.Environment.NewLine Dim boundaryBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(newLine & "--" & boundary & newLine) Dim request As Net.HttpWebRequest = Net.WebRequest.Create(Uri) request.ContentType = "multipart/form-data; boundary=" & boundary request.Method = "POST" request.Referer = "http://lok.myvnc.com/vivienda/casa-en-la-playa/insertar-anuncio.html" request.Headers.Add("Accept-Encoding", "gzip, deflate") request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0" request.CookieContainer = containa request.AllowAutoRedirect = True request.Timeout = -1 request.KeepAlive = True request.AllowWriteStreamBuffering = False Dim ms As New MemoryStream() Dim formDataTemplate As String = "Content-Disposition: form-data; name=""{0}""{1}{1}{2}" For Each key As String In otherParameters.Keys ms.Write(boundaryBytes, 0, boundaryBytes.Length) Dim formItem As String = String.Format(formDataTemplate, key, newLine, otherParameters(key)) Dim formItemBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(formItem) ms.Write(formItemBytes, 0, formItemBytes.Length) Next key ms.Write(boundaryBytes, 0, boundaryBytes.Length) Dim headerTemplate As String = "Content-Disposition: form-data; name=""{0}""; filename=""{1}""{2}Content-Type: {3}{2}{2}" Dim header As String = String.Format(headerTemplate, fileParameterName, filePath, newLine, contentType) Dim headerBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(header) ms.Write(headerBytes, 0, headerBytes.Length) Dim length As Long = ms.Length length += New FileInfo(filePath).Length request.ContentLength = length Using requestStream As IO.Stream = request.GetRequestStream() Dim bheader() As Byte = ms.ToArray() requestStream.Write(bheader, 0, bheader.Length) Using fileStream As New IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read) Dim buffer(4096) As Byte Dim bytesRead As Int32 = fileStream.Read(buffer, 0, buffer.Length) Do While (bytesRead > 0) requestStream.Write(buffer, 0, bytesRead) bytesRead = fileStream.Read(buffer, 0, buffer.Length) Loop End Using requestStream.Close() End Using Dim response As Net.WebResponse = Nothing Dim responseText = "" Try response = request.GetResponse() Using responseStream As IO.Stream = response.GetResponseStream() Using responseReader As New IO.StreamReader(responseStream) responseText = responseReader.ReadToEnd() End Using End Using Catch exception As Net.WebException MsgBox(exception.Message) Finally response.Close() response = Nothing request = Nothing End Try Return responseText End Function End Class
Bueno el codigo funciona perfecto cuando abro la pagina para ver si lo que publico todo bien menos la maldita imagen que no se porque no la sube.. ahora busque un Sniffer HTTP para ver a nivel de protoclo que sucede y hay varias cosas que note esto: Ejemplo de publicacion con el Firefox: -----------------------------265001916915724 Content-Disposition: form-data; name="ad_picture_a"; filename="corazon.jpg" Content-Type: image/jpeg 'Aqui va todo el archivo en codificado lenguaje maquina al server -----------------------------265001916915724 Y otros parametros que se envian pero que el Form no me pide ningun dato de ellos, sera eso lo que esta sucediendo?.. Me parece tambien que el modo de codificacion del archivo no es el mismo que el del Mozilla lo digo porque vi ambos ejemplos y no se parecen en nada, tambien quisiera saber si es obligatorio el orden en el que se mandan yo creo que no pero bueno... ahora algo que quiero dejar claro, el Form los datos que me exige son los que paso en el codigo quiero decir que si no pongo alguno de esos al dar click en el boton de enviar me vuelve a cargar la pagina señalandome los campos obligatorios, supongo entonces que si se publica entonces esos parametros que se envian junto con el form no son el problema en si...
|
|
|
643
|
Programación / .NET (C#, VB.NET, ASP) / Enviar un Form usando Httprequest !!
|
en: 12 Febrero 2013, 00:55 am
|
Amigos tengo un code con el que envio un FORM usando HTTPrequest con el metodo POST sin problemas, lo que sucede es que ese FORM tiene para mandar 3 fotos y ahi es donde se me traba el paraguas el CODE que tengo hasta ahora es este.. Imports System Imports System.IO Imports System.Net Imports System.Text Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim precio As String, categoria As String, titulo As String, cuerpo As String, _ filesize As String, email As String, phone As String 'Dim boundary As String = "---------------------------" + DateTime.Now.Ticks.ToString("x") ' Create the data we want to send precio = "25" categoria = "105" titulo = "titulo del form" cuerpo = "aki va el cuerpo del mensaje" email = "user@gnome.com" phone = "1234567" filesize = "307200" ' Create a request using a URL that can receive a post. Dim request As HttpWebRequest = HttpWebRequest.Create("URL") ' Set the Method property of the request to POST. request.Method = "POST" request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" Dim postdata As String = "ad_price=" & precio & "&category=" & categoria & "&ad_headline=" & _ titulo & "&ad_text=" & cuerpo & "&email=" & email & "&phone=" & phone & "&MAX_FILE_SIZE=" & filesize Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata) ' Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded" ' Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length ' Get the request stream. Dim dataStream As Stream = request.GetRequestStream() ' Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length) ' Close the Stream object. dataStream.Close() ' Get the response. Dim response As WebResponse = request.GetResponse() ' Display the status. Console.WriteLine(CType(response, HttpWebResponse).StatusDescription) ' Get the stream containing content returned by the server. dataStream = response.GetResponseStream() ' Open the stream using a StreamReader for easy access. Dim reader As New StreamReader(dataStream) ' Read the content. Dim responseFromServer As String = reader.ReadToEnd() ' Display the content. txtoutput.Text = responseFromServer ' Clean up the streams. reader.Close() dataStream.Close() response.Close() End Sub End Class
Muchas gracias por cualquier ayuda
|
|
|
644
|
Programación / .NET (C#, VB.NET, ASP) / Necesito anclar mi APP ?
|
en: 3 Febrero 2013, 02:19 am
|
Hola pues eso ando buscando algun dato en el Pc que nunca varie aunque formateen el Pc y reinstalen tambien que no se pueda simular en otra Pc, para que mi app lo verifique siempre antes de iniciar y nada mas corra en al Pc que yo quiera...
Tambien si es posible diganme algun metodo seguro para cifrar mi App, conozco el programa Armadillo pero no se si es necesario llegar hasta alla...
Salu2
|
|
|
645
|
Programación / .NET (C#, VB.NET, ASP) / SerialPort y Modem ?
|
en: 27 Enero 2013, 23:43 pm
|
Lo que espero es un Ok del Modem mas recibo un 65 alguna idea, quizas sea por el tipo de lectura que estoy haciendo....Salu2 Disculpen por repetir el Topic si pudieran borrar el otro estaria agradecido...gracias Imports System.IO.Ports Public Class Form1 Private mySerialPort As New SerialPort Private comBuffer As Byte() Private Delegate Sub UpdateFormDelegate() Private UpdateFormDelegate1 As UpdateFormDelegate Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try AddHandler mySerialPort.DataReceived, AddressOf mySerialPort_DataReceived CommPortSetup() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub mySerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) 'Handles serial port data received events UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay) Dim n As Integer = mySerialPort.BytesToRead 'find number of bytes in buf comBuffer = New Byte(n - 1) {} 're dimension storage buffer mySerialPort.Read(comBuffer, 0, n) 'read data from the buffer Me.Invoke(UpdateFormDelegate1) 'call the delegate End Sub Private Sub UpdateDisplay() Label2.Text = CStr(comBuffer(0)) End Sub Private Sub CommPortSetup() With mySerialPort .PortName = "COM3" .BaudRate = 9600 .DataBits = 8 .Parity = Parity.None .StopBits = StopBits.One .Handshake = Handshake.None End With Try mySerialPort.Open() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click mySerialPort.WriteLine("AT+VCID") End Sub End Class
|
|
|
646
|
Programación / .NET (C#, VB.NET, ASP) / Trabajando con Puerto COM - SerialPort !! Dudita !
|
en: 24 Enero 2013, 01:18 am
|
holas estoy tratando de leer la respuesta del Modem al comando que le paso y me devuelve un numero, no entiendo porque quizas sea en el tipo de lectura que se hace que es con un buffer.... Alguna idea...Lo que espero es un OK Imports System.IO.Ports Public Class Form1 Private mySerialPort As New SerialPort Private comBuffer As Byte() Private Delegate Sub UpdateFormDelegate() Private UpdateFormDelegate1 As UpdateFormDelegate Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try AddHandler mySerialPort.DataReceived, AddressOf mySerialPort_DataReceived CommPortSetup() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub mySerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) 'Handles serial port data received events UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay) Dim n As Integer = mySerialPort.BytesToRead 'find number of bytes in buf comBuffer = New Byte(n - 1) {} 're dimension storage buffer mySerialPort.Read(comBuffer, 0, n) 'read data from the buffer Me.Invoke(UpdateFormDelegate1) 'call the delegate End Sub Private Sub UpdateDisplay() Label2.Text = CStr(comBuffer(0)) End Sub Private Sub CommPortSetup() With mySerialPort .PortName = "COM3" .BaudRate = 9600 .DataBits = 8 .Parity = Parity.None .StopBits = StopBits.One .Handshake = Handshake.None End With Try mySerialPort.Open() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click mySerialPort.WriteLine("AT+VCID") End Sub End Class
|
|
|
647
|
Programación / .NET (C#, VB.NET, ASP) / Re: Necesito consultar la fecha en Internet ??
|
en: 15 Enero 2013, 01:32 am
|
Gracias en las busquedas que hice di con el, pero nose lo vi tan extenso que no me atrevi ni a testearlo, es que no creo que sea necesario tanto code para algo tan simple, digo yo... orita me lo llevo para la casa y hago las pruebas, lo estuve mirando por arriba y no vi como llamar a la funcion que revisa la fecha... bueno supongo que despues la vere, si tienes alguno mas simple te lo agradecere...
Orita no tendre ni con que agradecerte, jajajajaja.... bye
Te comento que ya casi tengo el proyecto listo...
Me falta poder generar unos reportes muy simples, tambien necesito poder eliminar cuentas de usuarios creadas en el Windows XP, asi como crear un grupo local y eliminarlos y otras boberias....
Salu2
|
|
|
648
|
Programación / .NET (C#, VB.NET, ASP) / Necesito consultar la fecha en Internet ??
|
en: 14 Enero 2013, 03:53 am
|
Holas chikos quizas alguno tenga algun codigo sobre consultar con algun server la fecha, es que el que tengo no me gusta...
Lo que hago es consultar una web y buscar en ella la fecha...
Se que hay un protocolo que atiende eso el NTP pero no encuentro un proyecto que me funcione sin problemas...
Salu2 y gracias cualquier idea...
|
|
|
649
|
Seguridad Informática / Bugs y Exploits / Re: DISEÑO DE EXPLOIT
|
en: 14 Enero 2013, 03:34 am
|
¿por que lo ayudan con esas cosas? no se supone que esas cosas están prohibidas en este foro??? o hay preferencias doblemoralistas ?
No le veo nada de malo a eso, hasta donde el pregunto no veo nada malo... Tampoco exageremos Salu2
|
|
|
650
|
Programación / .NET (C#, VB.NET, ASP) / Re: Problemilla con Sqlite !!
|
en: 21 Diciembre 2012, 17:33 pm
|
Tu problema ahora es que tienes valores no nullables a los cuales no les estas asignando nada Increible bueno pues si y no.... Lo que sucede es que tengo un campo de tipo Fecha que al parecer no le estoy pasando el formato de fecha correcto y me esta dando esa violacion, pq todos los tengo puesto como NULL jajajajaja, en cuanto cambie el campo ese por VARCHAR entro que jodia, un millon de gracias sos un barbaro... Dios te bendiga que tengas mucha dicha bro, salu2 Nos vemos orita con mas problemas jajajajaja
|
|
|
|
|
|
|