Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to edit a specified paste from the console
i have got the api of pastebin site but i dont know how to use it

What I have tried:

Public Class Pastebin
    Public Function NewPaste(ByVal Content As String)
        Dim api_dev_key As String = "" '<-- Your API key here
        Dim api_paste_code As String = URLEncode(Content)
        Dim api_paste_private As String = "2"
        'Dim api_paste_name As String = URLEncode(Name)
        Dim api_paste_expire_date As String = "10M"
        Dim api_paste_format As String = "php"
        Dim api_user_key As String = ""
        Dim Response As String = HttpPost("http://pastebin.com/api/api_post.php", "api_option=paste&api_dev_key=" & api_dev_key & "&api_paste_code=" & api_paste_code)
        If Response.Contains("Bad API request") = False Then
            Return Raw(Response)
        Else
            Return "Error"
        End If
    End Function
    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
    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
    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
End Class
Posted
Comments
[no name] 6-Jul-18 11:43am    
So you want to use the Pastebin API from a VB.NET console application. Please be more specific, most people won't be able to deduce that.

If Pastebin has provided a VB.NET example, they'll have documentation with it to tell you which methods to call, and how, to achieve different things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900