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 /
avatar image
0
Question by andersonaraujodl · Jul 29, 2019 at 11:00 PM · webglapi

[ERROR 405] Unity WebGL with 3rd part APIs

I'm working on a WebGL application made with Unity, that will be integrated with a external hardware.

The communication between them is being made by APIs, sent by a third part company (responsible for the hardware). They demanded everything to be sent by POST with an empty JSON as body "{}". The problem was that UnityWebRequest.Post doesn't format the JSON file properly.

The project was working perfectly with my local tests (accessing local JSON files), but when they sent the final API host address I had to work around to change the UnityWebRequest.Post to .Put, since the Post method doesn't format the JSON correctly. After some code changes, it is working on the Editor perfectly. The problem is when it comes to the Browser.

Bellow you can see what I've tried so far:

 IEnumerator GetJsonContent(string url)
 {
     var request = UnityWebRequest.Put(url, "{}");
     request.method = "POST";
 
     byte[] bodyRaw = Encoding.UTF8.GetBytes("{}");
     request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
     request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
     request.SetRequestHeader("Content-Type", "application/json");
 
     yield return request.SendWebRequest();
 
     while (!request.isDone)
     {
         yield return new WaitForEndOfFrame();
     }
 
     if (request.isNetworkError)
     {
         Debug.Log(request.error);
     }
     else
     {
         var jsonContent = request.downloadHandler.text;
 
         if (JsonCallback != null)
         {
             JsonCallback(jsonContent);
             JsonCallback = null;
         }
     }
 
     yield break;
 }

In addition to that code, I've also tried:

 var request = new UnityWebRequest(url, "POST");

Instead of the first two lines of the Coroutine.

The browser keeps throwing a 405 error, but the Postman returns values, but when I try to reproduce what I have on the browser on Postman, it says no "Body" is being sent.

The weirdest part is that it works perfectly fine on Unity (with the same API address).

Thanks in advance.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andersonaraujodl · Jul 30, 2019 at 07:23 PM

The problem was solved.

It was related to the CORS (Cross-Origin Resource Sharing). For some reason our server was not set to communicate with their server, so we had to change settings in our server. The code above works perfectly! :-)

Comment
Add comment · Share
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

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

113 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 avatar image

Related Questions

Use of HttpClient in WebGL export 0 Answers

Unity 5.3 WebGL with kongregate's API 2 Answers

XMLhttpRequest from origin has been blocked by CORS policy. 0 Answers

Can't Send a form to a server(POST) due to CORS error in a WEBGL build 1 Answer

Need help on APIs for my WebGL related project. 0 Answers


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