Downloading text from web gives html code.


So I managed to connect to the server and download data. The problem is I want the text from the file(.html or .txt), but when run the code it returns me html code. I did it with the www class. And used www.text.

Any ideas?


Well, it turns out your webserver / web framework does inject a html page infront of the actual content. That webpage is ment to set a cookie via Javascript and then immediately reloads the actual data with the suffix: News.html?ckattempt=1. This went by almost unnoticed when testing the link in the browser. However I use a local proxy that has a log window ^^.

So the problem is your webserver. It might has some kind of strange session management. Whatever it is, it is not compatible with your Unity application as you can’t execute (web) Javascript code code in your Unity application.

The only solution is to either:

  • find a better webserver / host which allows plain content access
  • find a way to disable this cookie inserting automatism.

The actual page returned is

    <script type="text/javascript" src="/aes.js" >
      function toNumbers(d){
        var e=[];
        return e}
      function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);
                       return e.toLowerCase()}
      var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("a67301d8765d38398ec776b3e21b132e");
      document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";
      This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support

Furthermore that page loads the aes.js file from your root which is used to decrypt the cookie content.

Hi there

It seems that what your server file contains is:

News: <color=reg>Test</color>
This is a test.

I’m not sure if you’re generating text on the server, but if what you want is genuinely just a text file, then store it as a ‘.txt’ file. Depending on the web server it may provide extra information about the file if you’re serving html. There’s no script I can see on that page though, so I’m guessing its just a plain text file you want?

I know quite a few developers who have done exactly that for their ‘news’ pages. Then if you want anything funky, you can just add a bit of your own ‘markup’ to your text file and interpret how you like on the client.