title: JMeter 3.2 file upload hitting ASP.Net as null file
body: <p>I'm using JMeter 3.2 to test my site.  I've used 2 prior versions, so I have some clue what I'm doing.</p>
  
  <p>I'm testing an ASP.NET 4.5 site.</p>
  
  <p>When I record a file upload I get a "fail" page back because my application is entering the "file uploaded" procedure, but the HttpPostedFileBase is null.</p>
  
  <p>The HTTP Request has everything filled out as I would expect it to be.</p>
  
  <pre><code>Method: POST
  Path: the /context/controller/action as expected
  Redirect Automatically unchecked
  Follow Redirects, Use KeepAlive, Use mutipart/form-data for POST, and Browser-compatible headers checked
  The File Path has the filename (no path info) as expected
  The Parameter Name is correct
  The MIME Type is correct
  </code></pre>
  
  <p>If I disconnect the proxy and upload the file it works just fine.</p>
  
  <p>If I stop recording, change the listener to Simple Controller, and playback the recorded session I can see that the "fail" page comes back.  It is a response status 200 because it's a user friendly error page, but I added an Assertion Response to capture the failed status.</p>
  
  <p>In the View Results Tree my request looks like this:</p>
  
  <pre><code>POST data:
  --xr9jIAHNizYdrOAAzOIT6Yuvtp-zJlfaoDdNP
  Content-Disposition: form-data; name="notInvolvedVariableName"
  
  false
  --xr9jIAHNizYdrOAAzOIT6Yuvtp-zJlfaoDdNP
  Content-Disposition: form-data; name="fileUploadVariableName"; filename="JustFileName.txt"
  Content-Type: text/plain
  
  &lt;actual file content, not shown here&gt;
  --xr9jIAHNizYdrOAAzOIT6Yuvtp-zJlfaoDdNP--
  
  Cookie Data:
  ASP.NET_SessionId=sessionIDblabla
  
  Request Headers:
  Connection: keep-alive
  Referer: THIS_STILL_HAS_HTTPS_AND_EXTERNAL_SERVER_IP_FROM_WHEN_I_RECORDED_THE_UPLOAD/UploadFile
  Accept-Language: en-US,en;q=0.5
  DNT: 1
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Upgrade-Insecure-Requests: 1
  Accept-Encoding: gzip, deflate, br
  User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0
  Content-Length: 9203
  Content-Type: multipart/form-data; boundary=xr9jIAHNizYdrOAAzOIT6Yuvtp-zJlfaoDdNP; charset=UTF-8
  Host: INTERNAL_IP
  </code></pre>
  
  <p>I was wondering if recording through HTTPS plays a role in the error.</p>
  
  <p>I know that my FileServer Base is pointing to the right folder (through checking the jmeter.log file and I tested it by changing the name in my HTTP Request which gave me the "File Not Found" IOException).</p>
  
  <p>I re-recorded the process using the internal path to see if that made a difference.  It didn't.  It still failed while recording.  The playback request does show the referrer as HTTP internal IP now.  But the playback still returns the fail page (a shocker since the fail page showed during recording).</p>
  
  <p>I looked at multiple "how to upload a file in JMeter" pages and they all say exactly what I'm doing.  Most pages never say what version they're referring to.</p>
  
  <p>I set the Debug Level to Debug and played it back again.  In the log file I see the headers and the file contents.  It is in readable text, not base64 or zipped (but I think that's OK.  In Fiddler the file content is readable as well).  The filename is in the header as expected.</p>
  
  <p>So it looks like the log is sending everything, but it's not making it to the server (during recording nor playback).  So what's going on?</p>
  
  <p>Edit:</p>
  
  <p>From Fiddler in the Headers:</p>
  
  <p>Manually (works)
      Content-Length: 9212
      Connection: keep=alive</p>
  
  <p>JMeter (doesn't work)
      Content-Length: 9188
      Content-Type contains charset=US-ASCII
      Connection: keep=alive
      Connection: Keep-Alive</p>
  
  <p>I'm not an expert, but I don't think the extra capitalized version of keep alive affects anything.
  I also doubt the charset sepcification affects anything.</p>
  
  <p>The content in the TextView looks identical to me.
  The content in the Raw view has the headers in a different order, but they're all essentially the same (with the extra Keep Alive in JMeter).</p>
  
  <p>Content Length doesn't include the header, but the body looks exactly the same other than boundry.
  The byte difference is coming from the difference in boundry length.
  It's 32 in JMeter and 40 manually.  It's in the content 3 times, adding up to 24.  That length changes each run, so I figure it shouldn't be the cause.</p>
  
  <p>So I am thinking one of your links is certainly the cause because it looks like everything is sending correctly.  I'm confused as to why it's received differently, but I'll read up and see where that gets me.</p>
  
  <p>Edit 2:</p>
  
  <p>I don't believe that it's a correlation issue.</p>
  
  <p>My action declaration is sanitized as this:</p>
  
  <pre><code>[ValidateInput(false)]
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult UploadFile(HttpPostedFileBase myFile)
  {
      logger.DebugFormat("Entered UploadFile with {0}", myFile != null ? myFile.FileName : "null filename");
      ...
  }
  </code></pre>
  
  <p>The log entry is saying "Entered UploadFile with null filename".</p>
  
  <p>On the regular GUI there's javascript that will prevent you from submitting without attaching a file.  JMeter doesn't run js, but everything tells me that JMeter IS sending the file.</p>
  
  <p>I added  to the web.config, and that made no difference.</p>
  
  <p>What else on IIS/ASP would be allowing the function call but blocking the file?</p>
  
  <p>I have another file upload where the function takes no params and it reaches into the Request object.</p>
  
  <pre><code>if (null != Request.Files &amp;&amp; Request.Files.Count &gt; 0)
  {
      HttpPostedFileBase hpf = Request.Files[0];
  }//if
  else
  {
      logger.DebugFormat("Entered UploadFile with null filename or 0 files");
  }
  </code></pre>
  
  <p>That one also fails to receive the file.</p>
  
  <p>Edit 3:</p>
  
  <p>I created a sample application where I am having this issue.  It logs to C:\Logs.</p>
  
  <p>NOTE: This link is superseded by a link below.
  <a href="http://s000.tinyupload.com/?file_id=49840904361057335433" rel="nofollow noreferrer">http://s000.tinyupload.com/?file_id=49840904361057335433</a></p>
  
  <p>Hit file upload in the bottom left.  I included a log in the zip.</p>
  
  <p>Just in case it was a FireFox issue I tried recording in IE and had the same problem.
  Edit 4:</p>
  
  <p>I loaded the test app onto another web server (just to make sure it wasn't something the original server was blocking).  I have the same results there.</p>
  
  <p>To help others use the test app above:</p>
  
  <p>So build the app attached above (Visual Sutio 2015).<br>
    Publish it (C:\Logs is where it will build). Zip Publish_WebApp1.<br>
    Deploy that to a web server (I'm using IIS 10 on the second server).<br>
    Try to record any file upload.<br>
    Check the log file.<br>
    Try uploading a file without the jmeter proxy (for comparison).</p>
  
  <p>Edit 5:
  I ran Wireshark on the second server.  I'm seeing a "Server 400 Bad Request: The request is badly formed" error. When I'm recording.</p>
  
  <p><a href="http://%20http://s000.tinyupload.com/?file_id=76890258829912351911" rel="nofollow noreferrer">http://s000.tinyupload.com/?file_id=76890258829912351911</a></p>
  
  <p>And then the packet showing the post looks like garbage (the highlighted post length 96).  In the manual run I can see the text of the uploaded file (see the post with length 907).  I can't upload this capture due to the nature of the file I uploaded, but I could repeat it with a sharable file if someone want to look at it.</p>
  
  <p>Edit 6:
  I added detail to the "post-upload" page in the sample site.</p>
  
  <p>I also made one big upload with the source code for the sample site, the compiled site, and a JMeter script.</p>
  
  <p><a href="http://s000.tinyupload.com/?file_id=08684297996175997497" rel="nofollow noreferrer">Sample Site with Code</a></p>
  
  <p>Visual Studio 2015:
  under projects I have the WebApplication1 source code zipped</p>
  
  <p>Logs:
  I have a sample log file with notes on wha tthe results look like.
  I have the zipped IIS-ready compiled web site.
  (unzip it into inetpub and promote the folder to an app)</p>
  
  <p>Temp:
  Has the jmeter script and the upload file.</p>
  
  <p>In JMeter change your HTTP Request Default to the IP of the web server
  I have a shortcut to run jmeterw.cmd from the Temp folder.
  (I'm not certain if that drives the FileServerBase or not, but my file is found)</p>
  
  <p>Though I'm still not certain if it's a JMeter bug or an IIS/ASP bug.</p>
  
  <p>Edit 7:</p>
  
  <p>Packet captures from the client and server <a href="http://s000.tinyupload.com/?file_id=94935134134663577067" rel="nofollow noreferrer">Packet Captures</a></p>
  
  <p>I just noticed that the Playback has "Content-Transfer-Encoding: binary", but normal and the recording do not.  However, uploading as binary should be fine in this case.  And even if the Type was wrong a corrupt file would still hit the server.</p>
  
  <p>Edit 8:</p>
  
  <p>The only differences that I can see are:</p>
  
  <p>JMeter adds "charset=US-ASCII" on the Content-Type</p>
  
  <p>JMeter adds "Content-Transfer-Encoding: binary" only on playback</p>
  
  <p>JMeter boundaries are 32 characters, and random</p>
  
  <p>Manual/working boundaries are 40 characters and start with lots of dashes</p>
  
  <p>The Wireshark captures show that JMeter posts of my sample file are always 4 frames.  around 650 bytes, 1450, 180, 38.  Where the end boundary is almost by itself in the last frame.  (from all of my fail captures that third frame is always 180, the others shift a bit)</p>
  
  <p>The manual posts of my sample file are always 3 frames.  around 450, 1450, 370.</p>
  
  <p>IMHO the charset and binary shouldn't matter.  I don't think frame count should matter.  But at this point I am reaching for straws as to why this doesn't work.  Could the boundary length really have something to do with it?</p>