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 /
This question was closed Aug 25, 2016 at 02:21 PM by utkudonertas for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by utkudonertas · Aug 24, 2016 at 01:16 PM · wwwjsongetrequestrest

I cant get response json from rest call in Unity

Hi all,

I had a problem while using www class for rest calls. I wrote the following code.

        void Start () 
        {
              WWW www = new WWW ("http://ip.jsontest.com/");
              StartCoroutine(WaitForRequest (www));
         }

         private IEnumerator WaitForRequest(WWW www) 
         {

              yield return www;

              // check for errors
              if (www.error == null) {
                 print (www.text);
              } else {
                     print ("error: "+www.error);
              }
         }

"http://ip.jsontest.com/" this url returns simple json that shows an ip.

Ex: { "ip": "193.202.18.14" }

But I didnt get that json in unity. What i get is below.

         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml">
         <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>IIS Windows Server</title>
         <style type="text/css">
         <!--
         body {
             color:#000000;
             background-color:#0072C6;
             margin:0;
         }

         #container {
             margin-left:auto;
             margin-right:auto;
             text-align:center;
             }

         a img {
             border:none;
         }

         -->
         </style>
         </head>
         <body>
         <div id="container">
         <img src="iis-85.png" alt="IIS"  />
         </div>
         </body>
         </html>
         UnityEngine.MonoBehaviour:print(Object)
         <WaitForRequest>c__Iterator0:MoveNext() (at Assets/ApplicationController.cs:56)
         UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

I have read many documents and I have tried many solutions but I couldn't solve it. How could i get that json?

Thanks,

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

  • Sort: 
avatar image
0
Best Answer

Answer by ScaniX · Aug 24, 2016 at 02:29 PM

At first I wanted to suggest the things below the line, but now I think you have some local problem. Did you try the same request using curl or any other program? I thought the headers might be the problem, but both curl and a request from within java HTTPUrlConnection return the expected contents.


I don't know what you have tried yet and cannot test it here, but you could try a different constructor to pass an "Accept: application/json" header value.

To keep it a GET request, check out this answer:

http://answers.unity3d.com/questions/63873/adding-header-info-to-www-get-method.html

Comment
Add comment · Show 1 · 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
avatar image utkudonertas · Aug 25, 2016 at 08:51 AM 0
Share

Yes, you are right it is a local problem. I didn't realize it before because i could send request via rest client tools such as "postman". But I realized that Firewall or proxy settings blocking my request. Now it works like a charm. Thanks.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom Header with WWW Get 0 Answers

GET Request dont save data 0 Answers

JSON Error : ArgumentException: JSON must represent an object type. 1 Answer

JsonUtility.FromJson cannot convert object from rest call 1 Answer

Json errors on unity 2017 (working on 5.6) 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