首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >unity的游戏端口: Web发布

unity的游戏端口: Web发布
EN

Stack Overflow用户
提问于 2015-06-03 18:08:52
回答 1查看 44关注 0票数 0

我正在将一个游戏从Java Native移植到Unity。虽然游戏运行正常,但我在使用相同的web服务发布比分时遇到了问题。

Java代码:

代码语言:javascript
复制
public static   String gameConfigURL = "http://192.168.0.140/services/scoreupload.svc/json/GetGameConfigurationLite";
public static   String scoreUploadURL = "http://192.168.0.140/services/scoreupload.svc/json/Upload";
public static final  String MagicKey = "0GmWDa6j"; 
private static  int timeoutConnection = 60000; 

 public static enum RequestSource
    { 
       Unknown,
        System, 
        Person; 
    } 

public static Response sendRequestForResult(Request request, String Url,
        Activity activity, Response response) throws JSONException,
        ClientProtocolException, IOException,ConnectTimeoutException {

    /** Code to create a JSON request from requestObject **/ 
    JSONObject object = request.getJSON();
    JSONObject requestObject = new JSONObject();
    requestObject.put("request", object);

    Log.v("","REQUEST:"+requestObject.toString());
    /** Add code to create a HttpPostRequest **/
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(Url);

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpResponse httpResponse = null;
    String jsonValueString = null;
    StringEntity se = null;
    try {
        se = new StringEntity(requestObject.toString());
    } catch (Exception e) {
        // TODO: handle exception 
        e.printStackTrace();
    }
    httpPost.setEntity(se);
    httpPost.setHeader("Accept", "application/json");
    httpPost.setHeader("Content-Type", "text/json"); 
    /**
     * add code to attach the JSON object received from request to the
     * HttpPostRequest Add Code to execute HttpRequest
     **/
    httpResponse = client.execute(httpPost);

    /** Get string from the HttpRespnse **/
    jsonValueString = EntityUtils.toString(httpResponse.getEntity());

    Log.v("","RESPONSE:"+jsonValueString);

    /** Create JSON object from incoming String **/
    JSONObject repliedObject = new JSONObject(jsonValueString);

    response.fromJSON(repliedObject);  
    return response;

如何将其转换为unity C#。

到目前为止,我有这样的想法:

代码语言:javascript
复制
JSONObject j = new JSONObject ();

    j.AddField ("Id", "1234567890");
    j.AddField ("MagicKey", ApplicationServices.magicKey); 
    j.AddField ("RequestedBy", "09996f84-1a06-e211-a518-001aa020d699");
    j.AddField ("Timestamp", "/Date(1547535370953)/"); 
    j.AddField ("RequestSource", "Person");
    j.AddField ("RequestedGameId", "375b43c0-91be-e011-a505-001aa020d699"); 
    j.AddField ("RequestedPersonId", "09996f84-1a06-e211-a518-001aa020d699");
    string json = j.ToString ();

    Dictionary<string, string> header = new Dictionary<string, string>();
    header.Add ("Accept", "application/json");
    header.Add ("Content-Type", "text/json");

    byte[] encode = Encoding.ASCII.GetBytes (json.ToCharArray ());


    WWW getConfig = new WWW (ApplicationServices.gameConfigURL, encode, header);

    yield return getConfig;

    if (getConfig.error != null) {
        Debug.Log (getConfig.error);
    } else {
        Debug.Log (getConfig.text);
    }

这似乎不起作用。

EN

回答 1

Stack Overflow用户

发布于 2015-06-03 21:06:05

对于"POST“,你应该使用WWWForm而不是WWW。

看一看here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30617054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档