i porting game java native unity. while game working correctly, having trouble posting score using same web services.
java code:
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 create json request requestobject **/ jsonobject object = request.getjson(); jsonobject requestobject = new jsonobject(); requestobject.put("request", object); log.v("","request:"+requestobject.tostring()); /** add code create 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 attach json object received request * httppostrequest add code execute httprequest **/ httpresponse = client.execute(httppost); /** string httprespnse **/ jsonvaluestring = entityutils.tostring(httpresponse.getentity()); log.v("","response:"+jsonvaluestring); /** create json object incoming string **/ jsonobject repliedobject = new jsonobject(jsonvaluestring); response.fromjson(repliedobject); return response; how convert unity c#.
so far have this:
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); } this not seem work.
for "post" should use wwwform instead of www.
take here
Comments
Post a Comment