Fix for: 500 Null Corrupt form data: no leading boundary

Another 500 Null Error / Solution

I ran into a strange error in the registration section of TheHealthChallenge.com where Internet Explorer users (Editors Note: Remove defamatory comments re: Internet Explorer Development Team and gratuitious comparisons about the size of their brains vs. size of their egos ) clicking a button would cause a 500 Null.

Here are the error details:

view plain print about
1500
2Corrupt form data: no leading boundary: != -----------------------------7d93d92a60680
3
4
5java.io.IOException: Corrupt form data: no leading boundary: != -----------------------------7d93d92a60680
6    at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:174)
7    at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:93)

Can anyone venture a guess as to what the problem was? You want more information? Take a look at the form code as well:

Here is the HTML for the Form:

view plain print about
1<form action="index.cfm?x=register" method="post" enctype="multipart/form-data" id="registerForm" class="uniForm">
2    <fieldset class="inlineLabels">
3        <div class="ctrlHolder">
4            <label for="register"> Need an Account?</label>
5            <p class="formHint">registration takes only 53 seconds</p>
6        </div>
7    </fieldset>
8        <div class="buttonHolder">
9            <button type="submit" class="submitButton">Start Registration</button>
10        </div>
11</form>

By the looks of the HTML code above, a single button will be drawn on the screen along with some friendly text. So why the error?

Solution

Apparently Internet Explorer does not handle serializing the form post if there is no content and what it sends to the server is not what the server expects. Possible resolutions for this are to remove the [enctype="multipart/form-data"] attribute or change the [method="post"] to [method="get"]. Either one will work as intended.

I happened to create this set of circumstances by using the CFUniform library in a way it was not designed for. I mentioned this to Matt Quackenbush who reworked the inner workings of the CFUniform Library to intelligently figure out if a file upload control is in the form or not. If one exists, the [enctype="multipart/form-data"] attribute will be included automatically. If you experience the 500 Null problem listed in this post, and you are using the CFUniform Library, simply update your version from http://cfuniform.riaforge.org/ and you'll be all set.

There are no comments for this entry.

Add Comment Subscribe to Comments

4/29/09 9:36 PM # Posted By Erik

I was getting a similar error message because I didn't specify the name attribute on my fields. Possibly adding a name to the submit button might also fix this issue.


9/7/09 1:34 PM # Posted By Nina

Thank you for your settings. Your advice - this is a godsend.


12/23/09 6:44 AM # Posted By karen

Internet explorer was bad and it will continue to be.Visit this site with ie


9/23/13 4:29 AM # Posted By Mohd Ilyas

I am posting multiple files through http post method from .Net application to Java Servelet Page and I am getting the Error:
N~java.io.IOException: Corrupt form data: no leading boundary: != ------------------------------8d08693613639c3

Can any body please & please help me out:
my code is :

public int postenrollments(string source, string posturl)
{

string[] enrolldirect;
int FindDirectoriesLength=System.IO.Directory.GetDirectories(source).Length ;
string SuccessUploadedFiles = ConfigurationManager.AppSettings.Get("UploadedEnrollmentsSource");
if (FindDirectoriesLength == 0)
{
status = 0;
}
else
{
enrolldirect = Directory.GetDirectories(source).ToArray();
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(posturl);

NameValueCollection nvc = new NameValueCollection();
nvc.Add("stTerminal", "000018112");
nvc.Add("stAgentID", "13220001");
nvc.Add("stvendorId", "112");

posturl += "?stTerminal=" + "000018112" + "&stAgentID=" + 13220001 + "&stvendorId=" + 112;
foreach (string dir in enrolldirect)
{
if (VerifyFiles(dir))
{
string[] enrollfiles = Directory.GetFiles(dir).ToArray();
UploadFile[] files = new UploadFile[enrollfiles.Length];
string[] filestoUpload = new string[enrollfiles.Length]; //This For PostMultipleFiles & UploadFilesToRemoteUrl Method
for (int i = 0; i < enrollfiles.Length; i++)
{
filestoUpload[i] = enrollfiles[i];//This For PostMultipleFiles & UploadFilesToRemoteUrl Method
files[i] = new UploadFile(enrollfiles[i]);

}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(posturl);



HttpWebResponse resp = UploadFilesToRemoteUrl(posturl, filestoUpload, "", nvc);




StreamReader respreader = new StreamReader(resp.GetResponseStream());
string response = respreader.ReadToEnd();

if (response.Trim() != "N~Invalid Terminal Id")
{
status = 1;
logmgr.Log("Directory :" + dir + "is uploaded");
if (!Directory.Exists(SuccessUploadedFiles))
{
Directory.CreateDirectory(SuccessUploadedFiles);///Main Directory Creation
}

}
else
{
status = 2;
logmgr.Log("Problem while Directory :" + dir + " upload");
}

}
else
{
logmgr.Log("Directory :" + dir + "is missing few files");
status = 3;
}
}
}
return status;
}

Method used to Post files

HttpWebResponse webResponse21;
public HttpWebResponse UploadFilesToRemoteUrl(string url, string[] files, string logpath, NameValueCollection nvc)
{

long length = 0;
string boundary = "----------------------------" +DateTime.Now.Ticks.ToString("x");


HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest2.ContentType = "multipart/form-data; boundary=" +boundary;
httpWebRequest2.Method = "POST";
httpWebRequest2.KeepAlive = true;
httpWebRequest2.Credentials = System.Net.CredentialCache.DefaultCredentials;

Stream memStream = new System.IO.MemoryStream();
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +boundary + "\r\n");
string formdataTemplate = "\r\n--" + boundary +"\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
foreach (string key in nvc.Keys)
{
string formitem = string.Format(formdataTemplate, key, nvc[key]);
byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
memStream.Write(formitembytes, 0, formitembytes.Length);
}


memStream.Write(boundarybytes, 0, boundarybytes.Length);

string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n";

for (int i = 0; i < files.Length; i++)
{

string header = string.Format(headerTemplate, "file" + i, files[i]);
//string header = string.Format(headerTemplate, "uplTheFile", files[i]);

byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);

memStream.Write(headerbytes, 0, headerbytes.Length);


FileStream fileStream = new FileStream(files[i], FileMode.Open,FileAccess.Read);
byte[] buffer = new byte[1024];

int bytesRead = 0;

while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
memStream.Write(buffer, 0, bytesRead);

}
memStream.Write(boundarybytes, 0, boundarybytes.Length);
fileStream.Close();
}

httpWebRequest2.ContentLength = memStream.Length;

Stream requestStream = httpWebRequest2.GetRequestStream();

memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
requestStream.Close();


webResponse21 = (HttpWebResponse)httpWebRequest2.GetResponse();

//Stream stream2 = webResponse21.GetResponseStream();
//StreamReader reader2 = new StreamReader(stream2);


//MessageBox.Show(reader2.ReadToEnd());

//webResponse2.Close();
//httpWebRequest2 = null;
//webResponse2 = null;
return webResponse21;
}


Add Comment Subscribe to Comments