Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WWW WebRequest UriFormatException:URI方案必须以字母开头,并且必须包含以下内容之一_C#_Unity3d_Web_Server - Fatal编程技术网

C# WWW WebRequest UriFormatException:URI方案必须以字母开头,并且必须包含以下内容之一

C# WWW WebRequest UriFormatException:URI方案必须以字母开头,并且必须包含以下内容之一,c#,unity3d,web,server,C#,Unity3d,Web,Server,在2017.2.0f3和2017.2.1f1版本中,每当运行下面列出的类中的行时,我都会遇到此错误,但是它在5.5.0.f3中工作得非常好 WWW request = new WWW(m_host, bytes, HashtableToDictionary<string, string>(postHeader)); 类生成错误: public class ServerRequest<T> : BaseServerRequest { public string G

在2017.2.0f3和2017.2.1f1版本中,每当运行下面列出的类中的行时,我都会遇到此错误,但是它在5.5.0.f3中工作得非常好

WWW request = new WWW(m_host, bytes, HashtableToDictionary<string, string>(postHeader));
类生成错误:

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);
    }
}
公共类ServerRequest:BaseServerRequest
{
公共弦乐游戏;
公共字符串内容;
[非串行化]
公共事业成功;
[非串行化]
公共服务器响应数据响应;
私有字符串m_主机;
私人业主;
private bool m_finished=false;
private bool m_running=false;
当前公共覆盖对象
{
得到
{
返回null;
}
}
公共服务器请求(字典内容、字符串游戏、字符串主机、所有者)
{
设置内容(content);
游戏=游戏;
m_host=主机;
this.owner=所有者;
}
公共IEnumerator进程()
{
Log(“发送数据…”);
UTF8Encoding=新的UTF8Encoding();
字符串json=TinyJson.JSONParser.ToJson(this);
Log(“发送Json…\n”+Json);
byte[]bytes=encoding.GetBytes(json);
Hashtable postHeader=新的Hashtable();
添加(“内容类型”、“文本/json”);
Add(“内容长度”,json);
WWW请求=新的WWW(m_主机,字节,哈希表字典(postHeader));
退换货请求;
if(请求==null)
{
成功=错误;
}
else if(request.error!=null)
{
成功=错误;
Debug.LogError(request.error);
}
其他的
{
成功=正确;
Log(“响应文本:+request.Text”);
字符串responseJson1=request.text.ReplaceAll(“\\n”,“\\\\n”).ReplaceAll(“\\t”,“\\\\t”);
Log(“响应文本2:+responseJson1”);
Response=TinyJson.JSONParser.FromJson(responseJson1);
Log(“响应:”);
Debug.Log(“\t内容:+Response.Content”);
Debug.Log(“\t成功:+Response.Successful”);
Debug.Log(“\tMessage:+Response.Message”);
}
m_finished=真;
}
公共静态字典HashtableToDictionary(哈希表)
{
返回表
.Cast()
.ToDictionary(kvp=>(K)kvp.Key,kvp=>(V)kvp.Value);
}
公共重写字符串ToString()
{
返回string.Format(“Response:Successfull={0},Content={1}”,Successfull,Response);
}
公共重写字符串ToJson()
{
返回string.Format(“{{\“Game\”:\“{0}\”,\“Content\”:{1}}}”,Game,Content);
}
公共覆盖bool MoveNext()
{
如果(!m_正在运行)
{
m_running=true;
owner.start例程(Process());
}
返回!m_完成;
}
公共覆盖无效重置()
{
//没有
}
公共内容(字典内容)
{
Content=TinyJson.JSONParser.ToJson(Content);
}
}

以前是否有其他人遇到过此错误并能够修复它?

问题是您未能指定URI方案(如
http
https

因此,你必须改变:

127.0.0.1:8888
致:


URI scheme是您向其发送请求的url(在本例中为
m_host
)scheme的值,例如,是“http”或“https”。当然还有很多其他的方案,尽管对于web,我认为您使用的是http或https。正如我今天已经告诉其他人的那样,除非您确定要放入JSON的内容,否则最好使用序列化程序。如果
Game
Content
突然包含引号,您的JSON将被破坏。@mjwills m\u主机是“127.0.0.1:8888”,JSON的值是:“{”Game\:“zv\”,“Content\:{”Call\“:“1\”,“Username\”:“,“Password\:\”:“\”}”为什么不使用JSON序列化程序而不是将其构建为字符串?
127.0.0.1:8888
http://127.0.0.1:8888