How to convert this CURL request to VB.NET code

Viewed 796

I am trying to upload a file to MixCloud using their API. In their documentation following curl request is the only example. I want this request to convert to VB.net WebRequest or other method. I need it in VB.net language. I tried everything including HttpResponseMessage but it reruns an error like bad request. Please help.

curl -F mp3=@upload.mp3 \
     -F "name=API Upload" \
     -F "tags-0-tag=Test" \
     -F "tags-1-tag=API" \
     -F "sections-0-chapter=Introduction" \
     -F "sections-0-start_time=0" \
     -F "sections-1-artist=Artist Name" \
     -F "sections-1-song=Song Title" \
     -F "sections-1-start_time=10" \
     -F "description=My test upload" \
     https://api.mixcloud.com/upload/?access_token=INSERT_ACCESS_TOKEN_HERE
1 Answers

I added VB.net code created using the method mentioned by @Martheen and I found the solution. Also I had to add

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

To allow TLS

This is final working code

Public Async Sub Upload(username As String, fileName As String, songTitle As String, description As String, accessToken As String)

    Try
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
        Using httpClient = New HttpClient()
            Using request = New HttpRequestMessage(New HttpMethod("POST"), "https://api.mixcloud.com/upload/?access_token=" & accessToken)
                Dim multipartContent = New MultipartFormDataContent()
                multipartContent.Add(New ByteArrayContent(File.ReadAllBytes(fileName)), "mp3", Path.GetFileName(fileName))
                multipartContent.Add(New StringContent(songTitle), "name")
                multipartContent.Add(New StringContent(description), "description")
                request.Content = multipartContent
                Dim response = Await httpClient.SendAsync(request)
            End Using
        End Using
    Catch ex As Exception
        MsgBox(ex.InnerException.Message)
    End Try

End Sub
Related