HTTP POS

Posted qi123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTTP POS相关的知识,希望对你有一定的参考价值。

string result = ""; 
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            Stream reqStream = null;
            StreamReader sr = null;
            try
            {  
                request = (HttpWebRequest)WebRequest.Create(url); 
                request.Method = "POST";
                request.Timeout = timeout * 1000;
                request.KeepAlive = false;  
                request.ContentType = "text/xml";
                byte[] data = System.Text.Encoding.UTF8.GetBytes(xml);
                request.ContentLength = data.Length;  
                reqStream = request.GetRequestStream();
                reqStream.Write(data, 0, data.Length); 
                Thread.Sleep(200);//不加入Sleep容易超时
                response = (HttpWebResponse)request.GetResponse(); 
                sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                result = sr.ReadToEnd().Trim();
            }
            catch (System.Threading.ThreadAbortException e)
            { 
                System.Threading.Thread.ResetAbort();
                return result;
            }
            catch (WebException e)
            {  
                return result;
            }
            catch (Exception e)
            { 
                return result;
            }
            finally
            {
                if (reqStream != null)
                {
                    reqStream.Close();
                }
                if (sr != null)
                {
                    sr.Close();
                } 
                if (response != null)
                {
                    response.Close();
                    response = null;
                }
                if (request != null)
                {
                    request.Abort();
                    request = null;
                }
            }
            return result;

 

以上是关于HTTP POS的主要内容,如果未能解决你的问题,请参考以下文章

HTTP POS

高效Web开发的10个jQuery代码片段

OpenGL着色器没有将变量从顶点传递到片段着色器

Flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform(代码片段

poj 1651 Multiplication Puzzle区间DP

如何从一个片段导航到另一个片段?