HttpRequest.Files is empty when posting file through HttpClient

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

Server-side:

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


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 02:55

    In case someone else has the same problem: make sure your boundary string is valid, e.g. don't do this:

    using (var content =
        new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
    {
            ...
    }
    

    This failed for me due to an invalid boundary character, maybe the "/" date separator. At least this solved my problem when accessing Context.Request.Files in a Nancy controller (which was always empty).

    Better to use something like DateTime.Now.Ticks.ToString("x") instead.

提交回复
热议问题