GetContentLength() public method

public GetContentLength ( ) : long
return long
Ejemplo n.º 1
0
        public virtual void OnHttpFinish(QQHttpResponse response)
        {
            try
            {
                string type = response.GetContentType() ?? "";
                if ((type.StartsWith("application/x-javascript")
                        || type.StartsWith("application/json")
                        || type.Contains("text")
                        ) && response.GetContentLength() > 0)
                {
                    MyLogger.Default.Debug(response.GetResponseString());
                }

                if (response.ResponseCode == QQHttpResponse.S_OK)
                {
                    OnHttpStatusOK(response);
                }
                else
                {
                    OnHttpStatusError(response);
                }
            }
            catch (QQException e)
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, e);
            }
            catch (JsonException e)
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.JSON_ERROR, e));
            }
            catch (Exception e)
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNKNOWN_ERROR, e));
            }
        }
Ejemplo n.º 2
0
 public override void OnHttpFinish(QQHttpResponse response)
 {
     //如果返回的内容为空,认为这次PollMsg仍然成功
     if (response.GetContentLength() == 0)
     {
         // LOG.debug("PollMsgAction: empty response!!!!");
         NotifyActionEvent(QQActionEventType.EVT_OK, new List<QQNotifyEvent>());
     }
     else
     {
         base.OnHttpFinish(response);
     }
 }
Ejemplo n.º 3
0
        public virtual void OnHttpFinish(QQHttpResponse response)
        {
            var type = response.GetContentType();
            if (type != null && (type.StartsWith("application/x-javascript")
                    || type.StartsWith("application/json")
                    || type.Contains("text")
                    ) && response.GetContentLength() > 0)
            {
                // Context.Logger.LogDebug(response.GetResponseString());
            }

            if (response.ResponseCode == QQHttpResponse.S_OK)
            {
                OnHttpStatusOK(response);
            }
            else
            {
                OnHttpStatusError(response);
            }
        }
Ejemplo n.º 4
0
        public Task<QQHttpResponse> ExecuteHttpRequest(QQHttpRequest request, IQQHttpListener listener)
        {
            return Task.Run(() =>
            {
                try
                {
                    var httpItem = new HttpItem()
                    {
                        KeepAlive = true,
                        ProtocolVersion = HttpVersion.Version10,
                        ContentType = "application/x-www-form-urlencoded; charset=UTF-8", // post方法的时候必须填写,要不然服务器无法解析
                        Encoding = Encoding.UTF8,
                        Allowautoredirect = true,
                        Method = request.Method,
                        URL = request.Url,
                        ReadWriteTimeout = (request.ReadTimeout > 0) ? request.ReadTimeout : 100000,
                        Timeout = (request.ConnectTimeout > 0) ? request.ConnectTimeout : 30000,
                        ResultType = ResultType.Byte,
                    };

                    if (request.HeaderMap.ContainsKey("User-Agent"))
                    {
                        httpItem.UserAgent = request.HeaderMap["User-Agent"];
                        request.HeaderMap.Remove("User-Agent");
                    }
                    if (request.HeaderMap.ContainsKey("Referer"))
                    {
                        httpItem.Referer = request.HeaderMap["Referer"];
                        request.HeaderMap.Remove("Referer");
                    }

                    foreach (var header in request.HeaderMap)
                    {
                        httpItem.Header.Add(header.Key, header.Value);
                    }
                    httpItem.CookieContainer = _cookieContainer;

                    if (request.Method.Equals("POST"))
                    {
                        if (request.FileMap.Count > 0)
                        {
                            httpItem.PostDataType = PostDataType.FilePath;
                            httpItem.Postdata = "";
                        }
                        else if (request.PostMap.Count > 0)
                        {
                            httpItem.PostDataType = PostDataType.String;
                            httpItem.Postdata = request.InputString;
                        }
                    }
                    else if (request.Method.Equals("GET"))
                    {

                    }
                    else
                    {
                        throw new QQException(QQErrorCode.IO_ERROR, "not support http method:" + request.Method);
                    }

                    HttpResult result = new HttpHelper().GetHtml(httpItem);
                    QQHttpResponse response = new QQHttpResponse()
                    {
                        ResponseMessage = result.StatusDescription,
                        ResponseCode = (int)result.StatusCode,
                        ResponseData = result.ResultByte,
                        Headers = new Dictionary<string, List<string>>(),
                    };
                    if (result.Header != null)
                    {
                        foreach (string header in result.Header)
                        {
                            response.Headers.Add(header, result.Header[header]);
                        }
                    }
                    if (result.CookieCollection != null)
                    {
                        _cookieContainer.Add(result.CookieCollection);
                    }

                    if (listener != null)
                    {
                        listener.OnHttpHeader(response);
                        listener.OnHttpRead(0, response.GetContentLength());
                        listener.OnHttpFinish(response);
                    }
                    return response;
                }
                catch (IOException e)
                {
                    throw new QQException(QQErrorCode.IO_ERROR, e);
                }
                catch (Exception e)
                {
                    throw new QQException(QQErrorCode.UNKNOWN_ERROR, e);
                }
            });
        }