C# 用jsp实现统一的web连接
这是我们的代码,我搞不懂这部分 WWW=newwww(“,pData,headers) 我们在标题中有一个错误 参数3:无法从“System.Collections.Hashtable”转换为“System.Collections.Generic.Dictionary”g非常清晰,但不是水晶 第三个参数声明为C# 用jsp实现统一的web连接,c#,json,jsp,unity3d,C#,Json,Jsp,Unity3d,这是我们的代码,我搞不懂这部分 WWW=newwww(“,pData,headers) 我们在标题中有一个错误 参数3:无法从“System.Collections.Hashtable”转换为“System.Collections.Generic.Dictionary”g非常清晰,但不是水晶 第三个参数声明为Dictionary,即使文本中显示“hashtable” 因此,不是: using UnityEngine; using System.Collections; using System.
Dictionary
,即使文本中显示“hashtable”
因此,不是:
using UnityEngine;
using System.Collections;
using System.Text;
public class Network : MonoBehaviour
{
// Use this for initialization
void Start()
{
Debug.Log("[waitforComm] Hello, World!");
string postData = "{\"waitforCommData\":1}";
Hashtable headers = new Hashtable();
headers.Add("Content-Type", "application/json");
byte[] pData = Encoding.ASCII.GetBytes(postData.ToCharArray());
WWW www = new WWW("http://localhost:8080/jspsample/process.jsp", pData, headers);
Debug.Log("[waitforComm] post message requested.");
StartCoroutine(waitforRequest(www));
}
// Update is called once per frame
void Update()
{ }
private IEnumerator waitforRequest(WWW www)
{
yield return www;
Debug.Log("[waitforComm] response : " + www.text);
}
}
做:
var headers=newdictionary();
添加(“内容类型”、“应用程序/json”);
你应该可以走了。g非常清晰,但不是水晶
第三个参数声明为Dictionary
,即使文本中显示“hashtable”
因此,不是:
using UnityEngine;
using System.Collections;
using System.Text;
public class Network : MonoBehaviour
{
// Use this for initialization
void Start()
{
Debug.Log("[waitforComm] Hello, World!");
string postData = "{\"waitforCommData\":1}";
Hashtable headers = new Hashtable();
headers.Add("Content-Type", "application/json");
byte[] pData = Encoding.ASCII.GetBytes(postData.ToCharArray());
WWW www = new WWW("http://localhost:8080/jspsample/process.jsp", pData, headers);
Debug.Log("[waitforComm] post message requested.");
StartCoroutine(waitforRequest(www));
}
// Update is called once per frame
void Update()
{ }
private IEnumerator waitforRequest(WWW www)
{
yield return www;
Debug.Log("[waitforComm] response : " + www.text);
}
}
做:
var headers=newdictionary();
添加(“内容类型”、“应用程序/json”);
你应该很乐意去做。它以前是
哈希表
,该代码曾经有效,但后来Unity将参数改为在较新版本中使用字典
。答案应该可以解决您的问题。@J.Choi-如果有任何答案解决了您的问题,请接受这个答案,这将有助于其他人找到直接答案并节省他们的时间:)它以前是哈希表
,该代码曾经是有效的,但Unity在较新版本中将参数改为采用字典
。答案应该可以解决你的问题。@J.Choi-如果有任何答案解决了你的问题,请接受这个答案,这将有助于其他人找到直接答案并节省他们的时间:)它解决得很好。非常感谢@崔先生很高兴这有帮助。有空的时候请接受这个答案。这个问题解决得很好。非常感谢@崔先生很高兴这有帮助。有空时请接受答案。
var headers = new Dictionary<string, string>();
headers.Add("Content-Type", "application/json");