Converting Curl command to Httpwebrequest in

Tahir Waheed 1 Reputation point

Hello Everyone,

I am new to!

I would like to convert this command to HTTPwebrequest in At first I want to test it locally and then run it from within docker.
However I am doing something wrong here and can't even test it locally.

curl --location --request POST "http://ip:port/copy" --header "Content-Type: application/json" --data-raw "{"file":"//path/Testfile.xlsx"}" >> Testfile.xlsx

I have read a few posts on the internet and tried the following.

Imports System.IO
Imports System.Net
Imports System.Text

Module Module1

    Sub Main()

        Dim request As WebRequest
        request = WebRequest.Create("http://ip:port/copy")
        Dim response As WebResponse
        Dim postData As String = "{"file":"//path/Testfile.xlsx"}" >> Testfile.xlsx"
        Dim data As Byte() = Encoding.UTF8.GetBytes(postData)

        request.Method = "POST"
        request.ContentType = "application/json"
        request.ContentLength = data.Length

        Dim stream As Stream = request.GetRequestStream()
        stream.Write(data, 0, data.Length)

        response = request.GetResponse()
        Dim sr As New StreamReader(response.GetResponseStream())


    End Sub

End Module

But I am not able to compile and run it because I am stuck at defining the correct data syntax which needs to be posted.
Am I not using the correct code ? please help me out in converting the mentioned curl command to
Thanks in Advance

Microsoft Technologies based on the .NET software framework.
3,602 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,658 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. faby m 1 Reputation point

    too late but:

    your string must be:

    Dim postData As String = "{""file"":""//path/Testfile.xlsx""}"

    and depending on what http://ip:port/copy expects you should put the new name/location in the json

    Dim postData As String = "{""file"":""path/Testfile.xlsx"",""destinationfile"":""newpath/newTestfile.xlsx""}"

    0 comments No comments