HttpRequest.Files is empty when posting file through HttpClient

前端 未结 4 2047
無奈伤痛
無奈伤痛 2020-12-06 02:29

Server-side:

    public HttpResponseMessage Post([FromUri]string machineName)
    {
        HttpResponseMessage result = null;
        var httpRequest = Http         


        
4条回答
  •  清歌不尽
    2020-12-06 02:40

    Everything looks good in your code except the content type which should be multipart/form-data. Please try changing your code to reflect the correct content type:

    content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
    

    You might want to refer to this post as to why setting the content type to application/octet-stream doesn't make sense from client side.

提交回复
热议问题