mercredi 29 juin 2016

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: enter image description here

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.

enter image description here

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




Aucun commentaire:

Enregistrer un commentaire