Skip to content

File Upload - multipart/form-data #860

@fiftycy

Description

@fiftycy

Hello am trying to figure out how to make this work. I want to do this request.

$ curl https://someaddress.com/
-F parameter1='abc123'
-F file=@myfile.someextension
-F parameter2='abc123'

And this is the code i use

var client = new RestClient("https://someaddress.com");

RestRequest request = new RestRequest("/",Method.POST);
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Accept", "application/json");

request.AddParameter("parameter1", "abc123");
request.AddParameter("parameter2", "abc123");

request.AddFile("fileData", fileStream.CopyTo, filename);
//request.AddFile("fileData", fileByteArray, filename);

var response= client.Execute(request);

Am always getting response with status code 0.
{"The underlying connection was closed: An unexpected error occurred on a send."}

This is the stacktrace that i can see inside the response ErrorException field.

InnerException = {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)
at RestSharp.Http.PostPutInternal(String method)

Any help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions