Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by RHooper · Jul 25, 2017 at 05:02 PM · jsonfailurepost

Need Assistance with JSON POST Failure in WebGL

I have a Class that is failing when running in WebGL but it works in the UNITY IDE 5.6.1f1 Personal (Plus) Edition. The code is 'trimmed' below, but contains the same characteristics (fails as a WebGL and runs w/ no issues in the UNITY IDE.) I'm pointing this to a service URL and get back a proper response when testing, but the Post actually never occurs when running from the WebGL and will crash when no response is ever received. I've posted a bug report to Unity but haven't received a response and would like to get thoughts from the community (maybe I need to set a specific build parameter or modify the code implementation?) Helpful feedback would be much appreciated.

---------------------------- Wrapper Class -----------------------------------

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class JsonTest : MonoBehaviour {

 JsonCommunicationManager jsonComm;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     
 }

 public void OnMouseDown()
 {

     var jsonCommunications = gameObject.AddComponent<JsonCommunicationManager>();
     string tempReturn = jsonCommunications.PostStartUpRequest("{\"userId\":1,\"id\":1}");
     Debug.Log("JSON RequestStartParms: Response :  " + tempReturn);

 }

}

----------------------------- JSON Utility Class ------------------------------------------

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class JsonCommunicationManager : MonoBehaviour {

 private WWW wwwForm;


 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {

 }

 public string PostStartUpRequest(string JsonPostMessage)
 {

     Debug.Log("Inside PostMessage:");

     string JsonReturnMessage;

     StartCoroutine(PostWWWMessage(JsonPostMessage));

     bool boolResponse = false;

     do
     {
         Debug.Log("Checking for Response ");
         try
         {
             JsonReturnMessage = wwwForm.text;
             boolResponse = true;
         }
         catch
         {
             WaitForResponse();
             Debug.Log("Inside JsonPost Message:  WAIT");
         }
     } while (!boolResponse);

     JsonReturnMessage = wwwForm.text;

     Debug.Log("Inside JsonPost Message: Messgae Response Received: ");
     Debug.Log("Inside JsonPost Message: Messgae Response Data: " + JsonReturnMessage);
     Debug.Log("Inside JsonPost Message: Messgae Response Received: ");
     Debug.Log("Inside JsonPost Message: Messgae Response Error: " + wwwForm.error);
     Debug.Log("Inside JsonPost Message: Messgae Response Received: ");

     return JsonReturnMessage;
 }

 //private void PostWWWMessage(string JsonPostMessage) {
 private IEnumerator PostWWWMessage(string JsonPostMessage)
 {

     Debug.Log("Inside PostWWWMessage:");
     Dictionary<string, string> headers = new Dictionary<string, string>();
     headers.Add("Content-Type", "application/json");
     byte[] postData = System.Text.Encoding.ASCII.GetBytes(JsonPostMessage.ToCharArray());
     string fullyQualifiedURL = "https://jsonplaceholder.typicode.com/posts";

     Debug.Log("Inside PostWWWMessage: Posting Message: " + JsonPostMessage);
     print("Posting start up request to: " + fullyQualifiedURL);
     print("Post Data is:                " + postData);
     print("Post Header is:              " + headers);
     wwwForm = new WWW(fullyQualifiedURL, postData, headers);

     WaitForResponse();

     yield return null;

 }

 private IEnumerator WaitForResponse()
 {
     yield return new WaitForSeconds(1);
 }



}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FunkyShammy · Jul 25, 2018 at 08:49 PM 0
Share

Did you find a solution for this cause i have the same issue and i have tried delaying the the coroutine thinking that that was the issue :S

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

POST JSON method does not work when project has been exported to WEBGL and upload to firebase,help please? 0 Answers

[WEBGL] Post json - complicated structure 0 Answers

Issue with sending Json via UnityWebRequest 0 Answers

Change Depth of Field in Unity while Runtime 0 Answers

JsonUtility :error CS0103: The name `JsonUtility' does not exist in the current context 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges