Страница: 1 |
|
Вопрос: работа с vkontakte
|
Добавлено: 18.10.09 19:50
|
|
Автор вопроса: maza_____ | Web-сайт: vkontakte.ru/id25563295 добавляйтесь в друзья)) | ICQ: 9968842
|
Всем привет! Подскажите пожалуйста какой нибудь пример работы с вконтакте на VB.NET или C#, хочу что нибудь для Вконтакта написать
Заранее благодарен.
Ответить
|
Номер ответа: 4 Автор ответа: Skywalker
ICQ: 300-70-6пятьЪ
Вопросов: 62 Ответов: 545
|
Web-сайт: iSkywalker.ru Профиль | | #4
|
Добавлено: 27.10.09 16:56
|
- Private Sub buttSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttSend.Click
- Dim b As Bitmap = pict.Image.Clone
- b = ResizeBitmap(b)
-
- pict.Image = b
- pict.Refresh()
- If filepictext = "png" Then
- pict.Image.Save(My.Application.Info.DirectoryPath + "\picture.png", Drawing.Imaging.ImageFormat.Png)
- Else
- pict.Image.Save(My.Application.Info.DirectoryPath + "\picture.jpg", Drawing.Imaging.ImageFormat.Jpeg)
- End If
- If filepictext = "png" Then
- SendPNG(id, My.Application.Info.DirectoryPath + "\picture.png")
- Else
- SendPNG(id, My.Application.Info.DirectoryPath + "\picture.jpg")
- End If
- mainFrm.WebBrowser1.Navigate("http://vkontakte.ru/graffiti.php?act=last")
- End Sub
- Public Function ResizeBitmap(ByVal b As Bitmap) As Bitmap
- If (b Is Nothing) Then Return Nothing
- Dim scale As Single
- Dim x As Single = 586 / b.Width
- Dim y As Single = 293 / b.Height
- If x < y Then scale = x Else scale = y
- If x >= 1 And y >= 1 Then scale = 1
- Dim result As Bitmap = New Bitmap(scale * b.Width, scale * b.Height, Imaging.PixelFormat.Format32bppRgb)
- Using g As Graphics = Graphics.FromImage(result)
- g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
- g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
- g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
-
-
-
-
- g.DrawImage(b, 0, 0, result.Width, result.Height)
- End Using
- Dim result2 As Bitmap = New Bitmap(586, 293)
- Using g As Graphics = Graphics.FromImage(result2)
- g.Clear(Color.White)
- g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
- g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
- g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- g.DrawImage(result, Convert.ToInt32(result2.Width / 2 - result.Width / 2), Convert.ToInt32(result2.Height / 2 - result.Height / 2))
- End Using
- Return result2
- End Function
- Private Function GetMD5Hash(ByVal input As String) As String
- Dim x As New System.Security.Cryptography.MD5CryptoServiceProvider()
- Dim bs() As Byte = System.Text.Encoding.UTF8.GetBytes(input)
- bs = x.ComputeHash(bs)
- Dim s As New System.Text.StringBuilder()
- For Each b As Byte In bs
- s.Append(b.ToString("x2").ToLower())
- Next
- Dim password As String = s.ToString()
- Return password
- End Function
- Private Function file_get_contents(ByVal fileName As String) As Byte()
- Dim sContents As Byte()
-
-
-
-
-
- Dim sr As New System.IO.StreamReader(fileName, System.Text.Encoding.GetEncoding(1251))
- sContents = System.Text.Encoding.GetEncoding(1251).GetBytes(sr.ReadToEnd)
- sr.Close()
-
- Return sContents
- End Function
- Private Sub SendPNG(ByVal to_id As String, ByVal filename As String)
- Dim sock As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
- sock.Connect("vkontakte.ru", 80)
- If sock.Connected Then
- Dim head As String = "POST /graffiti.php?to_id=" + to_id + "&group_id=0 HTTP/1.1" + vbNewLine
- head += "Host: vkontakte.ru" + vbNewLine
- head += "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7" + vbNewLine
- head += "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + vbNewLine
- head += "Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3" + vbNewLine
- head += "Accept-Encoding : gzip, deflate" + vbNewLine
- head += "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7" + vbNewLine
- head += "Keep-Alive: 300" + vbNewLine
- head += "Connection: keep-alive" + vbNewLine
- head += "Cookie: " + mainFrm.cookie + vbNewLine
- head += "Referer: http://vkontakte.ru/swf/Graffiti.swf?12" + vbNewLine
- head += "Content-type: multipart/form-data; boundary=--OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST" + vbNewLine
-
- Dim head2 As String = "----OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST" + vbNewLine
- head2 += "Content-Disposition: form-data; name=""Signature""" + vbNewLine + vbNewLine
- head2 += GetMD5Hash(Convert.ToBase64String(file_get_contents(filename)).Substring(0, 1024))
- head2 += vbNewLine
- head2 += "----OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST" + vbNewLine
- head2 += "Content-Disposition: form-data; name=""Filedata""; filename=""graffiti.png""" + vbNewLine
- head2 += "Content-Type: image/png" + vbNewLine + vbNewLine
- head2 += System.Text.Encoding.GetEncoding(1251).GetString(file_get_contents(filename))
- head2 += "----OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST" + vbNewLine
- head2 += "Content-Disposition: form-data; name=""Upload""" + vbNewLine
- head2 += vbNewLine
- head2 += "Submit Query" + vbNewLine
- head2 += "----OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST--"
-
- head += "Content-length: " + head2.Length.ToString + vbNewLine
- head += vbNewLine
- head += head2
-
-
-
-
-
- sock.Send(System.Text.Encoding.GetEncoding(1251).GetBytes(head))
- Dim header(1024) As Byte
- sock.Receive(header)
-
-
-
-
-
- Else
- MsgBox("Ошибка подключения к vkontakte.ru")
- End If
- sock.Close()
- End Sub
Ответить
|
Страница: 1 |
Поиск по форуму