Exemple #1
0
        //异步http请求
        public bool AsyncRequest(
            string url,
            string httpMethod,
            Oauthkey2 key,
            List <Parameter> listParam,
            List <Parameter> listFile,
            AsyncRequestCallback callback,
            out int callbkey)
        {
            Oauth oauth = null;

            oauth = new Oauth(key);

            string queryString = null;
            string oauthUrl    = oauth.GetOauthUrl(
                url,
                key.appKey,
                key.appSecret,
                key.tokenKey,
                key.callbackUrl,
                listParam,
                out queryString);

            AsyncHttp http = new AsyncHttp();

            callbkey = GetKey();
            CallbackInfo callbackInfo = new CallbackInfo();

            callbackInfo.key      = callbkey;
            callbackInfo.callback = callback;

            asyncRquestMap.Add(http, callbackInfo);

            bool bResult = false;

            if (httpMethod == "GET")
            {
                bResult = http.HttpGet(oauthUrl, queryString, new AsyncHttpCallback(HttpCallback));
            }
            else if ((listFile == null) || (listFile.Count == 0))
            {
                bResult = http.HttpPost(oauthUrl, queryString, new AsyncHttpCallback(HttpCallback));
            }
            else
            {
                bResult = http.HttpPostWithFile(oauthUrl, queryString, listFile, new AsyncHttpCallback(HttpCallback));
            }

            if (!bResult)
            {
                asyncRquestMap.Remove(http);
            }
            return(bResult);
        }
        //�첽http����
        public bool AsyncRequest(
            string url,
            string httpMethod,
            Oauthkey2 key,
            List<Parameter> listParam,
            List<Parameter> listFile,
            AsyncRequestCallback callback,
            out int callbkey)
        {
            Oauth oauth = null;

            oauth = new Oauth(key);

            string queryString = null;
            string oauthUrl = oauth.GetOauthUrl(
                url,
                key.appKey,
                key.appSecret,
                key.tokenKey,
                key.callbackUrl,
                listParam,
                out queryString);

            AsyncHttp http = new AsyncHttp();

            callbkey = GetKey();
            CallbackInfo callbackInfo = new CallbackInfo();
            callbackInfo.key = callbkey;
            callbackInfo.callback = callback;

            asyncRquestMap.Add(http, callbackInfo);

            bool bResult = false;

            if (httpMethod == "GET")
            {
                bResult = http.HttpGet(oauthUrl, queryString, new AsyncHttpCallback(HttpCallback));
            }
            else if ((listFile == null) || (listFile.Count == 0))
            {
                bResult = http.HttpPost(oauthUrl, queryString, new AsyncHttpCallback(HttpCallback));
            }
            else
            {
                bResult = http.HttpPostWithFile(oauthUrl, queryString, listFile, new AsyncHttpCallback(HttpCallback));
            }

            if (!bResult)
            {
                asyncRquestMap.Remove(http);
            }
            return bResult;
        }