Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将此CURL请求转换为VB.NET代码_Vb.net_Visual Studio_Api_Curl - Fatal编程技术网

如何将此CURL请求转换为VB.NET代码

如何将此CURL请求转换为VB.NET代码,vb.net,visual-studio,api,curl,Vb.net,Visual Studio,Api,Curl,我正在尝试使用他们的API将一个文件上传到MixCloud。在他们的文档中,以下curl请求是唯一的示例。我希望将此请求转换为VB.net WebRequest或其他方法。我需要它在VB.net语言。我尝试了所有方法,包括HttpResponseMessage,但它会重新运行一个错误,比如坏请求。请帮忙 curl -F mp3=@upload.mp3 \ -F "name=API Upload" \ -F "tags-0-tag=Test&quo

我正在尝试使用他们的API将一个文件上传到MixCloud。在他们的文档中,以下curl请求是唯一的示例。我希望将此请求转换为VB.net WebRequest或其他方法。我需要它在VB.net语言。我尝试了所有方法,包括HttpResponseMessage,但它会重新运行一个错误,比如坏请求。请帮忙

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

我添加了使用@Martheen提到的方法创建的VB.net代码,我找到了解决方案。我还要补充一点

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
允许TLS

这是最终的工作代码

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

然后把它整理好,然后做你的实际代码,即使它不起作用。谢谢你,我会尝试它。为了帮助其他人快速找到解决方案,当他们有类似的问题,你可以考虑分享你的答案,然后回答。@ XingyuZhao感谢小费。我补充了答案。