1

I'm trying to upload a file to the hosting platform Lutim using C#. In their documentation (https://git.framasoft.org/luc/lutim/wikis/API) they are using a cURL call:

curl -F "format=json" -F "file=@/tmp/snap0001.jpg" https://lut.im

And get back the following response:

{
    "success": true,
    "msg": {
        "real_short": "abc",
        "short": "abc/def",
        "token": "ghijkl",
        "thumb": XXX,
        "filename": "myimage.png"
    }
}

When I'm using WebClient, HttpWebRequest or WebRequest, like in this sample:

using (WebClient uploader = new WebClient())
{
   var data = uploader.UploadFile(new Uri(url), fileName);
   var result = System.Text.Encoding.Default.GetString(data);
}

I always get back the HTML content of the target page, and not a JSON response as with the cURL call.

How can I get the same behavior of the cURL call in C#? (without having to call cURL from C#...)

NicoC
  • 437
  • 1
  • 6
  • 17

1 Answers1

1

You're not supplying both form-data parts. You're missing the "format=json" part.

Have a look at

for ways to pass both values

Community
  • 1
  • 1
AndyPook
  • 2,137
  • 18
  • 22