Пример #1
0
    public int SendRequest(string url, string request, string param, float timeout,
                           HttpManager.OnResponseDelegate onResponse, HttpManager.OnRequestTimeoutDelegate onTimeout)
    {
        int id = this.GenerateId();

        Debug.Log("Url:" + url);
        Debug.Log("Request:" + request);
        HttpSession session =
            new HttpSession(id, "POST", url, request, param, timeout,
                            "application/x-www-form-urlencoded; charset=UTF-8", onResponse, onTimeout);

        session.Start();
        this.sessionList.Add(session);
        return(id);
    }
Пример #2
0
 public HttpSession(int id, string method, string url, string requestData,
                    string param, float fTimeout, string contentType = "application/Json",
                    HttpManager.OnResponseDelegate onResponse        = null, HttpManager.OnRequestTimeoutDelegate onTimeout = null)
 {
     this.id                    = id;
     this.httpRequest           = (HttpWebRequest)WebRequest.Create(url);
     this.httpRequest.Method    = method;
     this.requestData           = Encoding.UTF8.GetBytes(requestData);
     this.bCompleted            = false;
     this.param                 = param;
     this.fTimeout              = fTimeout;
     this.onResponse            = onResponse;
     this.onTimeout             = onTimeout;
     this.httpRequest.KeepAlive = false;
     this.responseData          = new StringBuilder(string.Empty);
     this.response              = null;
     this.contentType           = contentType;
 }