2017-12-29 59 views
1

のいずれかでなければなりません。以下の行を上記のクラスから実行すると、2017.2.0f3と2017.2.1f1でこのエラーが発生しますが、中5.5.0.f3WWW WebRequest UriFormatException:URIスキームは文字で始まっていなければならず、

WWW request = new WWW(m_host, bytes, HashtableToDictionary<string, string>(postHeader)); 

ERROR:

UriFormatException: URI scheme must start with a letter and must consist of one of alphabet, digits, '+', '-' or '.' character. 
System.Uri.Parse (UriKind kind, System.String uriString) 
System.Uri.ParseUri (UriKind kind) 
System.Uri..ctor (System.String uriString, Boolean dontEscape) 
System.Uri..ctor (System.String uriString) 

クラス生成エラー:

public class ServerRequest<T> : BaseServerRequest 
{ 
    public string Game; 
    public string Content; 

    [NonSerialized] 
    public bool Successful; 
    [NonSerialized] 
    public ServerResponseData<T> Response; 

    private string m_host; 
    private MonoBehaviour owner; 

    private bool m_finished = false; 
    private bool m_running = false; 

    public override object Current 
    { 
     get 
     { 
      return null; 
     } 
    } 

    public ServerRequest(Dictionary<string, object> content, string game, string host, MonoBehaviour owner) 
    { 
     SetContent(content); 
     Game = game; 
     m_host = host; 
     this.owner = owner; 
    } 

    public IEnumerator Process() 
    { 
     Debug.Log("Sending Data..."); 
     UTF8Encoding encoding = new UTF8Encoding(); 

     string json = TinyJson.JSONParser.ToJson(this); 
     Debug.Log("Sending Json...\n" + json); 

     byte[] bytes = encoding.GetBytes(json); 

     Hashtable postHeader = new Hashtable(); 
     postHeader.Add("Content-Type", "text/json"); 
     postHeader.Add("Content-Length", json); 


     WWW request = new WWW(m_host, bytes, HashtableToDictionary<string, string>(postHeader)); 
     yield return request; 

     if (request == null) 
     { 
      Successful = false; 
     } 
     else if (request.error != null) 
     { 
      Successful = false; 
      Debug.LogError(request.error); 
     } 
     else 
     { 
      Successful = true; 
      Debug.Log("Response Text: " + request.text); 

      string responseJson1 = request.text.ReplaceAll("\\n", "\\\\n").ReplaceAll("\\t", "\\\\t"); 
      Debug.Log("Response Text2: " + responseJson1); 
      Response = TinyJson.JSONParser.FromJson<ServerResponseData<T>>(responseJson1); 

      Debug.Log("Response: "); 
      Debug.Log("\tContent: " + Response.Content); 
      Debug.Log("\tSuccessful: " + Response.Successful); 
      Debug.Log("\tMessage: " + Response.Message); 
     } 

     m_finished = true; 
    } 

    public static Dictionary<K, V> HashtableToDictionary<K, V>(Hashtable table) 
    { 
     return table 
      .Cast<DictionaryEntry>() 
      .ToDictionary(kvp => (K)kvp.Key, kvp => (V)kvp.Value); 
    } 

    public override string ToString() 
    { 
     return string.Format("Response: Successfull = {0}, Content = {1}", Successful, Response); 
    } 

    public override string ToJson() 
    { 
     return string.Format("{{ \"Game\": \"{0}\", \"Content\": {1} }}", Game, Content); 
    } 

    public override bool MoveNext() 
    { 
     if (!m_running) 
     { 
      m_running = true; 
      owner.StartCoroutine(Process()); 
     } 
     return !m_finished; 
    } 

    public override void Reset() 
    { 
     // Nope 
    } 

    public void SetContent(Dictionary<string, object> content) 
    { 
     Content = TinyJson.JSONParser.ToJson(content); 
    } 
} 

このエラーが発生する前に他の誰かが遭遇し、修正できましたか?

+0

URIスキームはあなたが、 – AVAVT

+0

スキーム(m_host' 'この場合の値)にリクエストを送っているURLですたとえば、「http」または「https」です。もちろん、他の多くのスキームが存在しますが、Webではhttpやhttpsを使っていると思います。 – john

+1

そして、私がすでに他の人に話してきたように、あなたがJSONに入れるコンテンツが確実でない限り、シリアライザを使うのが一番です。 'Game'や' Content'が突然引用符を含んでいた場合、あなたのJSONは壊れてしまいます。 – john

答えて

2

問題は、URIスキーム(httpまたはhttpsなど)を指定できなかったことです。

このように変更する必要があります。

127.0.0.1:8888 

へ:

http://127.0.0.1:8888 
関連する問題