Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Implementare la creazione di file pastebin
- 'Per i parametri da usare visualizzare il pastebin "Pastebin API parameter" http://pastebin.com/QMfR6gpJ
- 'For API Key: http://pastebin.com/api
- 'Funzione per creare il file Pastebin
- 'Function to make a Pastebin file
- Public Function NewPaste(ByVal Content As String)
- Dim api_dev_key As String = "" '<-- La tua API key \ Your API Key
- Dim api_user_name As String = "" '<-- Il tuo Username \ Your Username
- Dim api_user_password As String = "" '<-- La tua Password \ Your Password
- Dim api_paste_code As String = URLEncode(Content)
- Dim api_paste_private As String = "2" '<-- Public=0, Unlisted=1, Private=2
- Dim api_paste_name As String = URLEncode("") '<-- Il nome per il file di testo da creare \ Pastebin File Name
- Dim api_paste_expire_date As String = "N" '<-- Durata del file (N = Mai) \ Expire Date (N = Never)
- Dim api_paste_format As String = "text" '<-- Formato (text = None) \ Format (text = None
- Dim api_user_key As String = HttpPost("http://pastebin.com/api/api_login.php", "api_dev_key=" & api_dev_key & "&api_user_name=" & api_user_name & "&api_user_password=" & api_user_password)
- Dim Response As String = HttpPost("http://pastebin.com/api/api_post.php", "api_option=paste&api_user_key=" & api_user_key & "&api_paste_private=" & api_paste_private & "&api_paste_name=" & api_paste_name & "&api_paste_expire_date=" & api_paste_expire_date & "&api_paste_format=" & api_paste_format & "&api_dev_key=" & api_dev_key & "&api_paste_code=" & api_paste_code)
- 'Se il server crea il pastebin produce il link in formato Raw altrimenti dà Error
- 'If the server build the pastebin, the function produces the link in Raw format, otherwise it gives Error
- If Response.Contains("Bad API request") = False Then
- Return Raw(Response)
- Else
- Return "Error"
- End If
- End Function
- 'La funzione UrlEncode serve per non inserire errori nella stringa da dare all'URL
- 'The function UrlEncode need to delete errors in the string to give the URL
- Private Function URLEncode(ByVal EncodeStr As String) As String
- Dim i As Integer
- Dim erg As String
- erg = EncodeStr
- erg = Replace(erg, "%", Chr(1))
- erg = Replace(erg, "+", Chr(2))
- For i = 0 To 255
- Select Case i
- Case 37, 43, 48 To 57, 65 To 90, 97 To 122
- Case 1
- erg = Replace(erg, Chr(i), "%25")
- Case 2
- erg = Replace(erg, Chr(i), "%2B")
- Case 32
- erg = Replace(erg, Chr(i), "+")
- Case 3 To 15
- erg = Replace(erg, Chr(i), "%0" & Hex(i))
- Case Else
- erg = Replace(erg, Chr(i), "%" & Hex(i))
- End Select
- Next
- Return erg
- End Function
- 'La funzione Raw restituisce l'URL del pastebin in formato Raw
- 'The function Raw returns the URL of the pastebin in Raw format
- Public Function Raw(ByVal URL As String)
- Dim ID As String = URL.Substring(URL.LastIndexOf("/") + 1)
- ID = "http://pastebin.com/raw.php?i=" & ID
- Return ID
- End Function
- 'La funzione HttpPost Serve per mandare le chiamate al server
- 'The HttpPost function is used to send calls to the server
- Private Function HttpPost(ByVal URL As String, ByVal Data As String)
- Dim request As WebRequest = WebRequest.Create(URL)
- request.Method = "POST"
- Dim byteArray As Byte() = Encoding.UTF8.GetBytes(Data)
- request.ContentType = "application/x-www-form-urlencoded"
- request.ContentLength = byteArray.Length
- Dim dataStream As Stream = request.GetRequestStream()
- dataStream.Write(byteArray, 0, byteArray.Length)
- dataStream.Close()
- Dim response As WebResponse = request.GetResponse()
- 'Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
- dataStream = response.GetResponseStream()
- Dim reader As New StreamReader(dataStream)
- Dim responseFromServer As String = reader.ReadToEnd()
- reader.Close()
- dataStream.Close()
- response.Close()
- Return responseFromServer
- End Function
- 'In seguito puoi implementare le funzioni per poter, per esempio, generare il link in una Textbox premendo su un pulsante
- 'Later can implement the functions to be able to, for example, generate the link in a Textbox by pressing on a button
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim pastebin_string As String = "Text File Content by Pizzul" + vbNewLine + vbNewLine + "Thanks for this"
- Textbox1.Text = NewPaste(pastebin_string)
- End Sub
Add Comment
Please, Sign In to add comment