Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Protocol "http not supported or disabled in libcurl

Discussion in 'Scripting' started by mediumTaj, Jul 26, 2015.

  1. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Hello,
    I'm trying to load a texture from the web onto a UI element and I get an error
    "You are trying to load data from a www stream which had the following error when downloading.
    Protocol "http not supported or disabled in libcurl"

    I don't see much on the web about this. Has anybody run into this issue before? Here is sample code I'm using (don't mind the image - It's a sample image from json who's load is failing for me):

    Code (CSharp):
    1. private string url="http://i.telegraph.co.uk/multimedia/archive/03387/President-Barack-O_3387037b.jpg";
    2. private IEnumerator setImage() {
    3.         ASCIIEncoding asciiEncoding = new ASCIIEncoding();
    4.         byte[] bytes = asciiEncoding.GetBytes(url);
    5.         string clean = asciiEncoding.GetString(bytes);
    6.  
    7.         WWW www = new WWW(clean);
    8.         yield return www;
    9.         RawImage ri = gameObject.GetComponent<RawImage>();
    10.         ri.texture = www.texture;
    11.     }
    Any help would be greatly appreciated!
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    After copying and pasting it, I had absolutely no problems running this script. Copy the URL from your own post here and paste it back into the script to see if it has some sort of formatting that's messing it up... Also, I used the fully-qualified name for the ASCIIEncoding class (System.Text.ASCIIEncoding) so I wouldn't have to include the namespace it's in, so try that?
     
  3. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Hmm, you're right! the script works when I hardcode the URL. I should have tried that before posting. In my project the url is parsed from json. I thought it may be the order in which I'm executing but I put a waitforseconds at the top of the script and I get the same error. Anything else I might be missing?
     
  4. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    As I said, the code you posted works fine. That being the case, the error is from something you haven't posted. You just said that the url is parsed from json- you need to escape the string so that an extra ' or " in there doesn't interfere with processing that string, maybe? If you want further help for this, you really need to post the code that's giving you a problem, which is not what's up here.
     
    mediumTaj likes this.
  5. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Sure thing... Here's a little test I made that is failing for me. i'm using jsonObject from the asset store
    (https://kharma.unity3d.com/en/#!/content/710). Thanks for your help!

    Code (CSharp):
    1. //    add this sript to Canvas element with RawImage
    2. //    using jsonObject plugin from https://kharma.unity3d.com/en/#!/content/710
    3.  
    4. using UnityEngine;
    5. using System.Collections;
    6. using System.Net;
    7. using System.Text;
    8. using UnityEngine.UI;
    9.  
    10. public class JSONTest : MonoBehaviour {
    11.     public string search = "barack obama";
    12.     private string url = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=8&q=";
    13.     private string imgUrl;
    14.    
    15.     void Start () {
    16.         Search();
    17.     }
    18.    
    19.     private void Search() {
    20.         GetData(Utils.escape(search));
    21.     }
    22.  
    23.     void GetData(string search) {
    24.         string searchURL = url + search;
    25.         Debug.Log(searchURL);
    26.         WWW www = new WWW(url + search);
    27.         StartCoroutine(WaitForRequest(www));
    28.     }
    29.    
    30.     IEnumerator WaitForRequest(WWW www) {
    31.         while(!www.isDone);
    32.         yield return www;
    33.        
    34.         if(www.error == null) {
    35.             Debug.Log("REQUEST SUCCESS!");
    36. //            JSONObject j = JSONObject.Create(WWW.UnEscapeURL(www.text));
    37.             JSONObject j = JSONObject.Create(www.text);
    38.             Debug.Log(j);
    39.             ParseData(j);
    40.         } else {
    41.             Debug.Log("REQUEST ERROR!");
    42.             Debug.Log(www.error);
    43.         }
    44.     }
    45.  
    46.     void ParseData(JSONObject o) {
    47.         imgUrl = o["responseData"]["results"][0]["image"]["url"].ToString();
    48.         StartCoroutine(setImage ());
    49.     }
    50.  
    51.     private IEnumerator setImage() {
    52. //        yield return new WaitForSeconds(3);
    53.         ASCIIEncoding asciiEncoding = new ASCIIEncoding();
    54.         byte[] bytes = asciiEncoding.GetBytes(imgUrl);
    55.         string clean = asciiEncoding.GetString(bytes);
    56.        
    57.         WWW www = new WWW(clean);
    58.         yield return www;
    59.         RawImage ri = GameObject.Find(gameObject.name + "/RawImage").GetComponent<RawImage>();
    60.         ri.texture = www.texture;
    61.     }
    62. }
    63.  
     
  6. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Oops i forgot a little helper class

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Text;
    4. using System;
    5.  
    6. public class Utils : MonoBehaviour {
    7.     public static string escape(object @string)
    8.     {
    9.         string str = Convert.ToString(@string);
    10.         string str2 = "0123456789ABCDEF";
    11.         int length = str.Length;
    12.         StringBuilder builder = new StringBuilder(length * 2);
    13.         int num3 = -1;
    14.         while (++num3 < length)
    15.         {
    16.             char ch = str[num3];
    17.             int num2 = ch;
    18.             if ((((0x41 > num2) || (num2 > 90)) &&
    19.                  ((0x61 > num2) || (num2 > 0x7a))) &&
    20.                 ((0x30 > num2) || (num2 > 0x39)))
    21.             {
    22.                 switch (ch)
    23.                 {
    24.                 case '@':
    25.                 case '*':
    26.                 case '_':
    27.                 case '+':
    28.                 case '-':
    29.                 case '.':
    30.                 case '/':
    31.                     goto Label_0125;
    32.                 }
    33.                 builder.Append('%');
    34.                 if (num2 < 0x100)
    35.                 {
    36.                     builder.Append(str2[num2 / 0x10]);
    37.                     ch = str2[num2 % 0x10];
    38.                 }
    39.                 else
    40.                 {
    41.                     builder.Append('u');
    42.                     builder.Append(str2[(num2 >> 12) % 0x10]);
    43.                     builder.Append(str2[(num2 >> 8) % 0x10]);
    44.                     builder.Append(str2[(num2 >> 4) % 0x10]);
    45.                     ch = str2[num2 % 0x10];
    46.                 }
    47.             }
    48.         Label_0125:
    49.                 builder.Append(ch);
    50.         }
    51.         return builder.ToString();
    52.     }
    53. }
    54.  
     
  7. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    One of the updates apparently has to do with escaped quotes, which would explain this problem. I'm not sure if they updated the scripts on the AssetStore or if you got the updated version if they did, but here's the link:
    http://wiki.unity3d.com/index.php?title=JSONObject
     
    mediumTaj likes this.
  8. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Wow! I didn't even notice those quotes! It makes so much sense now since the full error is:

    You are trying to load data from a www stream which had the following error when downloading.
    Protocol "http not supported or disabled in libcurl

    I thought it just missed the close quotes somewhere.

    I tested by replacing the ParseData function with

    Code (CSharp):
    1. voidParseData(JSONObjecto) {
    2. stringtempURL = o["responseData"]["results"][0]["image"]["url"].ToString();
    3. string[] temp = tempURL.Split('\"');
    4. imgUrl = temp[1];
    5. StartCoroutine(setImage ());
    6. }
    The quotes are removed from the URL and everything seems to be working fine. Thanks for your help Lysander!!
     
  9. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    ...im sure theres a better way to remove those quotes - quick and dirty version for now!