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.

“ip”: “”

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">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>IIS Windows Server</title>
        <style type="text/css">
        body {

        #container {

        a img {

        <div id="container">
        <img src="iis-85.png" alt="IIS"  />
        <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?


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: