I want to call an API from another API and post file in that API as a form-data but file is not posting returning 204 No Content message, How to do?

33 views Asked by At

In attached image this is my code returning 204 no content message, I want success message 200 code but don't know how?

public HttpResponseMessage MakePostAsync()
{
    string apiUrl = "https://abc.c9api.in/api/method/upload_file";
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
    string filepath = @"C:\Users\Javed.shaikh\Desktop\CSVFiles\SalesOrderDetail.csv";
    var content = new MultipartFormDataContent();

    client.DefaultRequestHeaders.Add("Authorization", "Token f802cc75fabec4770:62fa1ba5aff78bbfc4d");
    content.Add(new StringContent("0"), "is_private");
    content.Add(new StringContent("Home"), "folder");
    var fileContent = new StreamContent(new FileStream(filepath, FileMode.Open));
    fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
    fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
    {
        Name = "file",
        FileName = "SalesOrderDetail.csv"
    };
    content.Add(fileContent);
    request.Content = content;
    Task<HttpResponseMessage> result = client.SendAsync(request);
    return new HttpResponseMessage()
    {
        Content = new StringContent("Response: ", System.Text.Encoding.UTF8, "application/json"),
        StatusCode = HttpStatusCode.OK
    };
}
0

There are 0 answers