Blank web server response in multiple type data submission

When I attach image resources to web service api call, its giving me blank server side response as well nothing submitted to server as well.

I was using following code for this purpose:

IEnumerator RegisterVoterProfile ()
	{
		WWW localFile = new WWW ("file:///Users/gaminguruz/Desktop/messi.jpg");
		yield return localFile;

		if (localFile.error == null)
			Debug.Log ("Loaded file successfully");
		else {
			Debug.Log ("Open file error: " + localFile.error);
			yield break; // stop the coroutine here
		}

		Dictionary<string,string> headerDisc = new Dictionary<string, string> ();
//		headerDisc.Add ("Content-Type", "multipart/form-data");
		headerDisc.Add ("Api-Key", "Api-Key Paste Here");

		WWWForm form = new WWWForm ();
		form.AddField (GameConstants.REGISTRATION_USERNAME_ARG, userNameInput.text);
		form.AddField (GameConstants.REGISTRATION_PASSWORD_ARG, passwordInput.text);
		form.AddField (GameConstants.REGISTRATION_EMAIL_ARG, emailInput.text);
		form.AddBinaryData (GameConstants.REGISTRATION_PROFILE_PIC_ARG, localFile.bytes);
		form.AddField (GameConstants.REGISTRATION_USERTYPE_ARG, GameConstants.VOTER_USER_TYPE);
		byte[] rawData = form.data;

		WWW www = new WWW (GameConstants.REGISTRATION_BASE_URL, rawData, headerDisc);
		yield return www;

		if (www.error == null) 
			Debug.Log ("Data: " + www.text);    
		else 
			Debug.Log ("Error: " + www.error);
	}

Attaching output image too:

73168-screen-shot-2016-06-29-at-35458-pm.png

If I remove following line from source code then data get submitted over and get proper response as well.
Even if I just upload image only then also task completed successfully.

form.AddBinaryData (GameConstants.REGISTRATION_PROFILE_PIC_ARG, localFile.bytes);

Even in PostMan and DHC all things working perfectly.

Now at which place, I was doing mistake that I can’t able to find so please help me in this.

The way you setup your headers is a bit wrong. The WWWForm class will setup the basic header information which you ignore since you pass your own header dictionary. The general procedure when applying cusom headers is this:

WWWForm form = new WWWForm();
// add your form data here
form.AddField(...);
// [...]

var headers = form.headers;
// add your custom headers here
headers.Add(..., ...);

// Send your request
WWW www = new WWW ( ... , form.data, headers);
yield return www;

The default headers contain the proper “content type” which is determined from the actual form data. A multipart content type needs a boundary marker which is created by the WWWForm class and is used to seperate the different parts. The boundary marker is a random 40 character string that is generated in the WWWForm internally. When reading the “data” property the WWWForm uses this internally generated boundary marker to seperate the parrs. The content type header need the same boundary marker or the request won’t work.

The “headers” property of the WWWForm class looks like this:

public Dictionary<string, string> headers
{
	get
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		if (this.containsFiles)
		{
			dictionary["Content-Type"] = "multipart/form-data; boundary=\"" + Encoding.UTF8.GetString(this.boundary, 0, this.boundary.Length) + "\"";
		}
		else
		{
			dictionary["Content-Type"] = "application/x-www-form-urlencoded";
		}
		return dictionary;
	}
}