当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextWriter.Close方法代码示例

本文整理汇总了C#中Jayrock.Json.JsonTextWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.Close方法的具体用法?C# JsonTextWriter.Close怎么用?C# JsonTextWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jayrock.Json.JsonTextWriter的用法示例。


在下文中一共展示了JsonTextWriter.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post

        // Return error code
        public int Post(string url, JsonTextWriter json)
        {
            WebRequest request = WebRequest.Create (serverURL+url);

              request.Method = "POST";

            json.AutoComplete();

            string text = json.ToString();

            Log.Write("Request: ");
            Log.WriteLine (text.ToString()+"\n");

            json.Close();

              byte[] postdata = System.Text.Encoding.ASCII.GetBytes (text);

            request.ContentLength = postdata.Length;

            // Wait one second when 60th RPC call is made during minute
            if (Interlocked.Read(ref throttle) == 60)
            {
                if (onMessage != null && severity >= 6)
                    onMessage(this,"[{0}] Throttling...", DateTime.Now);
                while (Interlocked.Read(ref throttle) == 60)
                    Thread.Sleep(1000);
            }

            if (timer.Enabled) Interlocked.Increment(ref throttle);

            try {
                Stream stream = request.GetRequestStream ();

              	stream.Write (postdata, 0, postdata.Length);
              	stream.Close ();
            } catch (System.Net.WebException ex) {
                if (onMessage != null && severity >= 3) onMessage(this,ex.Message);
                return -1;
            }

            if (onMessage != null && severity >= 7)
                onMessage(this,"\n[{0}] Connecting...",DateTime.Now);

            try {
              	WebResponse response = request.GetResponse ();
                ProcessResponse(response);
                if (onServerStatus != null) onServerStatus(this,new ServerStatusEventArgs());
            } catch (System.Net.WebException ex) {
                if (Regex.IsMatch(ex.Response.ContentType,"json-rpc")) {
                  WebResponse response = ex.Response;
                    ProcessResponse(response);
                    ServerErrorEventArgs args =
                        new ServerErrorEventArgs(r.error.code,r.error.data,r.error.message);
                    if (onServerError != null) onServerError(this,args);
                    return r.error.code;
                } else {
                    if (onMessage != null && severity >= 3) onMessage(this,ex.Message);
                    return -1;
                }
            }
            return 0;
        }
开发者ID:remy22,项目名称:C--Games-Lacuna-Client,代码行数:63,代码来源:Session.cs

示例2: Post

        private string Post(string url, JsonTextWriter json)
        {
            while (rpcCount > 50)
            { }//This creates the wait time until rpc count is reset.
            if (url == null) throw new Exception("URL is not assigned a value!");

            WebRequest request = WebRequest.Create(serverURL + url);
            request.Method = "POST";
            json.AutoComplete();
            string text = json.ToString();
            WriteStringToLog("request");
            WriteStringToLog(text);
//            log.WriteLine("Request");
//
            //Log.Write("Request: ");
            //Log.WriteLine(text.ToString() + "\n");

            json.Close();
            try
            {
            // Create a request using a URL that can receive a post. 
           // WebRequest request = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx ");
            // Set the Method property of the request to POST.
            //request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = text;
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse();
                // Display the status.
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            //Console.WriteLine(responseFromServer);
            //Console.ReadKey();
            // Clean up the streams.
            WriteStringToLog("response");
            WriteStringToLog(responseFromServer);
           
            reader.Close();
            dataStream.Close();
            response.Close();
            rpcCount++;

            if (ServerResponseEvent != null)  //deserializes the server response and passes it out as an event.
            {
                JavaScriptSerializer js = new JavaScriptSerializer();  
                Response r = js.Deserialize<Response>(responseFromServer);
                if (r.id == 101)
                {
                    sessionID = r.result.session_id;
                    Console.WriteLine(sessionID);
                }

                ServerResponseEvent(this, r);
            }
            //log.WriteLine("Response");
            WriteStringToLog("Response");
            //log.WriteLine(responseFromServer);
            WriteStringToLog(responseFromServer);
            return responseFromServer;
            }
            catch
            {
                WriteStringToLog("Post function failure");
                //log.WriteLine("Post function failure");
                //log.Close();
                string failure = "failure";
                return failure;
            }

        }
开发者ID:Jazzeroki,项目名称:JazzTools,代码行数:87,代码来源:LEWrapper.cs


注:本文中的Jayrock.Json.JsonTextWriter.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。