/** * testAPI */ //testAPI comment one //testAPI comment two public async Task TestAPIAsync() { Dictionary <string, object> runtime_ = new Dictionary <string, object>() { // empty runtime comment // another runtime comment }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); // new model instance comment Test1 modelInstance = new Test1 { // test declare front comment Test = "test", // test2 declare front comment Test2 = "test2", }; // number declare comment int?num = 123; // static function call comment Client.StaticFunc(); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); // static async function call await Client.TestFuncAsync(); // return comment return; } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
internal async Task RefreshAccessTokenAsync() { TeaRequest request = new TeaRequest(); request.Protocol = "http"; request.Method = "POST"; request.Pathname = "/v2/oauth/token"; request.Headers = new Dictionary <string, string>(); request.Headers.Add("host", GetHost(this.endpoint, this.domainId + ".api.alicloudccp.com")); request.Headers.Add("content-type", "application/x-www-form-urlencoded; charset=utf-8"); request.Headers.Add("date", TimeUtils.GetGMTDate()); request.Headers.Add("accept", "application/json"); request.Headers.Add("x-acs-signature-method", "HMAC-SHA1"); request.Headers.Add("x-acs-signature-version", "1.0"); string bodyStr = string.Format("grant_type=refresh_token&refresh_token={0}&client_id={1}&client_secret={2}", this.refreshToken, this.clientId, this.clientSecret); MemoryStream stream = new MemoryStream(); byte[] bytes = Encoding.UTF8.GetBytes(bodyStr); await stream.WriteAsync(bytes, 0, bytes.Length); request.Body = stream; TeaResponse response = await TeaCore.DoActionAsync(request, new Dictionary <string, object>()); string body = TeaCore.GetResponseBody(response); Dictionary <string, object> bodyDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(body); if (response.StatusCode == 200) { expireTime = DictUtils.GetDicValue(bodyDict, "expire_time").ToSafeString(); accessToken = DictUtils.GetDicValue(bodyDict, "access_token").ToSafeString(); refreshToken = DictUtils.GetDicValue(bodyDict, "refresh_token").ToSafeString(); } }
public async Task HelloAsync() { TeaRequest request_ = new TeaRequest(); request_.Method = "GET"; request_.Pathname = "/"; request_.Headers = new Dictionary <string, string> { { "host", "www.test.com" }, }; TeaResponse response_ = await TeaCore.DoActionAsync(request_); return; }
public async Task HelloRuntimeAsync() { Dictionary <string, object> runtime_ = new Dictionary <string, object>() { }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); request_.Method = "GET"; request_.Pathname = "/"; request_.Headers = new Dictionary <string, string> { { "host", "www.test.com" }, }; _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); return; } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
public async Task HelloVirtualCallAsync(M m) { m.Validate(); TeaRequest request_ = new TeaRequest(); request_.Method = "GET"; request_.Pathname = "/"; request_.Headers = new Dictionary <string, string> { { "key", "" }, }; TeaResponse response_ = await TeaCore.DoActionAsync(request_); return; }
public async Task <Dictionary <string, object> > Complex2Async(ComplexRequest request, List <string> str, Dictionary <string, string> val) { request.Validate(); TeaRequest request_ = new TeaRequest(); string name = "complex"; Darabonba.import.Models.Config config = new Darabonba.import.Models.Config(); Darabonba.import.Client client = new Darabonba.import.Client(config); request_.Protocol = "HTTP"; request_.Port = 80; request_.Method = "GET"; request_.Pathname = "/"; request_.Query = new Dictionary <string, string> { { "date", "2019" }, { "protocol", request_.Protocol }, }; TeaResponse response_ = await TeaCore.DoActionAsync(request_); return; }
public async Task HelloAsync() { TeaRequest request_ = new TeaRequest(); request_.Method = "GET"; request_.Pathname = "/"; request_.Headers = new Dictionary <string, string> { { "host", "www.test.com" }, }; string host = request_.Headers.Get("host"); if (true) { request_.Headers["host"] = "www.test2.com"; } TeaResponse response_ = await TeaCore.DoActionAsync(request_); HelloIf(); return; }
public async Task <ComplexRequest> Complex3Async(ComplexRequest request) { request.Validate(); TeaRequest request_ = new TeaRequest(); string name = "complex"; request_.Protocol = await TemplateStringAsync(); request_.Port = 80; request_.Method = "GET"; request_.Pathname = "/"; request_.Body = TeaCore.BytesReadable("body"); request_.Query = new Dictionary <string, string> { { "date", "2019" }, }; TeaResponse response_ = await TeaCore.DoActionAsync(request_); if (true) { throw new TeaRetryableException(request_, response_); } TeaResponse resp = response_; Darabonba.import.Models.Request req = new Darabonba.import.Models.Request { Accesskey = request.AccessKey, Region = resp.StatusMessage, }; Array0(request.ToMap()); req.Accesskey = "accesskey"; req.Accesskey = request.AccessKey; await PrintNullAsync(typeof(Config)); Darabonba.import.Common.Array(request.ToMap(), "1"); return(TeaModel.ToObject <ComplexRequest>(TeaConverter.merge <string> ( request_.Query ))); }
public async Task <Dictionary <string, object> > Complex2Async(ComplexRequest request, List <string> str, Dictionary <string, string> val, List <List <List <string> > > complexList) { request.Validate(); TeaRequest request_ = new TeaRequest(); string name = "complex"; Darabonba.import.Models.Config config = new Darabonba.import.Models.Config(); Darabonba.import.Client client = new Darabonba.import.Client(config, "testSecond"); Darabonba.import.Models.Request.RequestSubmodel subModel = new Darabonba.import.Models.Request.RequestSubmodel(); List <List <List <List <string> > > > nestingList = new List <List <List <List <string> > > > { new List <List <List <string> > > { new List <List <string> > { new List <string> { "test" } } } }; request_.Protocol = "HTTP"; request_.Port = 80; request_.Method = "GET"; request_.Pathname = "/"; request_.Query = new Dictionary <string, string> { { "date", "2019" }, { "protocol", request_.Protocol }, }; return(new Dictionary <string, object>() { }); TeaResponse response_ = await TeaCore.DoActionAsync(request_); return; }
public async Task <AlipayPassInstanceUpdateResponse> UpdateInstanceAsync(string serialNumber, string channelId, string tplParams, string status, string verifyCode, string verifyType) { Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "connectTimeout", 15000 }, { "readTimeout", 15000 }, { "retry", new Dictionary <string, int?> { { "maxAttempts", 0 }, } }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); Dictionary <string, string> systemParams = new Dictionary <string, string> { { "method", "alipay.pass.instance.update" }, { "app_id", this._kernel.GetConfig("appId") }, { "timestamp", this._kernel.GetTimestamp() }, { "format", "json" }, { "version", "1.0" }, { "alipay_sdk", this._kernel.GetSdkVersion() }, { "charset", "UTF-8" }, { "sign_type", this._kernel.GetConfig("signType") }, { "app_cert_sn", this._kernel.GetMerchantCertSN() }, { "alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN() }, }; Dictionary <string, object> bizParams = new Dictionary <string, object> { { "serial_number", serialNumber }, { "channel_id", channelId }, { "tpl_params", tplParams }, { "status", status }, { "verify_code", verifyCode }, { "verify_type", verifyType }, }; Dictionary <string, string> textParams = new Dictionary <string, string>() { }; request_.Protocol = this._kernel.GetConfig("protocol"); request_.Method = "POST"; request_.Pathname = "/gateway.do"; request_.Headers = new Dictionary <string, string> { { "host", this._kernel.GetConfig("gatewayHost") }, { "content-type", "application/x-www-form-urlencoded;charset=utf-8" }, }; request_.Query = this._kernel.SortMap(TeaConverter.merge <string> ( new Dictionary <string, string>() { { "sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey")) }, }, systemParams, textParams )); request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams)); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); Dictionary <string, object> respMap = await this._kernel.ReadAsJsonAsync(response_, "alipay.pass.instance.update"); if (this._kernel.IsCertMode()) { if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap)))) { return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(this._kernel.ToRespModel(respMap))); } } else { if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey"))) { return(TeaModel.ToObject <AlipayPassInstanceUpdateResponse>(this._kernel.ToRespModel(respMap))); } } throw new TeaException(new Dictionary <string, string> { { "message", "验签失败,请检查支付宝公钥设置是否正确。" }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
/** * Encapsulate the request and invoke the network * @param action api name * @param protocol http or https * @param method e.g. GET * @param pathname pathname of every api * @param request which contains request params * @param runtime which controls some details of call api, such as retry times * @return the response */ public async Task <Dictionary <string, object> > DoRequestAsync(string action, string protocol, string method, string pathname, Dictionary <string, object> request, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "timeouted", "retry" }, { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) }, { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) }, { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) }, { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) }, { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) }, { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) }, { "retry", new Dictionary <string, object> { { "retryable", runtime.Autoretry }, { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) }, } }, { "backoff", new Dictionary <string, object> { { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") }, { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) }, } }, { "ignoreSSL", runtime.IgnoreSSL }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol); request_.Method = method; request_.Pathname = pathname; request_.Query = new Dictionary <string, string> { { "method", action }, { "version", "1.0" }, { "sign_type", "HmacSHA1" }, { "req_time", AntChain.AlipayUtil.Client.GetTimestamp() }, { "req_msg_id", AlibabaCloud.TeaUtil.Common.GetNonce() }, }; if (!AlibabaCloud.TeaUtil.Common.Empty(_tenant)) { request_.Query["tenant"] = _tenant; } if (!AlibabaCloud.TeaUtil.Common.Empty(_workspace)) { request_.Query["workspace"] = _workspace; } if (!AlibabaCloud.TeaUtil.Common.Empty(_authToken)) { request_.Query["auth_token"] = _authToken; } else { request_.Query["access_key"] = _accessKeyId; } request_.Headers = new Dictionary <string, string> { { "host", _endpoint }, { "user-agent", GetUserAgent() }, }; Dictionary <string, object> tmp = AlibabaCloud.TeaUtil.Common.AnyifyMapValue(AlibabaCloud.Commons.Common.Query(request)); request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToFormString(tmp)); request_.Headers["content-type"] = "application/x-www-form-urlencoded"; Dictionary <string, string> signedParam = TeaConverter.merge <string> ( request_.Query, AlibabaCloud.Commons.Common.Query(request) ); request_.Query["sign"] = AntChain.AlipayUtil.Client.GetSignature(signedParam, _accessKeySecret); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); object obj = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body); Dictionary <string, object> res = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj); Dictionary <string, object> resp = AlibabaCloud.TeaUtil.Common.AssertAsMap(res.Get("response")); if (AntChain.AlipayUtil.Client.HasError(res)) { throw new TeaException(new Dictionary <string, object> { { "message", resp.Get("result_msg") }, { "data", resp }, { "code", resp.Get("result_code") }, }); } return(resp); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
/** * Send request * @param pathname the url path * @param protocol http or https * @param method example GET * @param header request header * @param body the object of IoTApiRequest * @param runtime which controls some details of call api, such as retry times * @return the response */ public async Task <TeaResponse> DoRequestAsync(string pathname, string protocol, string method, Dictionary <string, string> header, IoTApiRequest body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { body.Validate(); Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "timeouted", "retry" }, { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) }, { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) }, { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) }, { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) }, { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) }, { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) }, { "retry", new Dictionary <string, object> { { "retryable", runtime.Autoretry }, { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) }, } }, { "backoff", new Dictionary <string, object> { { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") }, { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) }, } }, { "ignoreSSL", runtime.IgnoreSSL }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol); request_.Method = AlibabaCloud.TeaUtil.Common.DefaultString(method, "POST"); request_.Pathname = pathname; request_.Headers = TeaConverter.merge <string> ( new Dictionary <string, string>() { { "host", _domain }, { "date", AlibabaCloud.TeaUtil.Common.GetDateUTCString() }, { "x-ca-nonce", AlibabaCloud.TeaUtil.Common.GetNonce() }, { "x-ca-key", _appKey }, { "x-ca-signaturemethod", "HmacSHA256" }, { "accept", "application/json" }, { "user-agent", GetUserAgent() }, }, header ); if (AlibabaCloud.TeaUtil.Common.Empty(body.Id)) { body.Id = AlibabaCloud.TeaUtil.Common.GetNonce(); } if (!AlibabaCloud.TeaUtil.Common.IsUnset(body.ToMap())) { request_.Headers["content-type"] = "application/octet-stream"; request_.Headers["content-md5"] = AlibabaCloud.APIGatewayUtil.Common.GetContentMD5(AlibabaCloud.TeaUtil.Common.ToJSONString(body.ToMap())); request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToJSONString(body.ToMap())); } request_.Headers["x-ca-signature"] = AlibabaCloud.APIGatewayUtil.Common.GetSignature(request_, _appSecret); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); return(response_); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
public async Task <AlipayOpenApiGenericResponse> ExecuteAsync(string method, Dictionary <string, string> textParams, Dictionary <string, object> bizParams) { Dictionary <string, object> runtime_ = new Dictionary <string, object>() { { "connectTimeout", 15000 }, { "readTimeout", 15000 }, { "retry", new Dictionary <string, int?>() { { "maxAttempts", 0 }, } }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); Dictionary <string, string> systemParams = new Dictionary <string, string>() { { "method", method }, { "app_id", _getConfig("appId") }, { "timestamp", _getTimestamp() }, { "format", "json" }, { "version", "1.0" }, { "alipay_sdk", _getSdkVersion() }, { "charset", "UTF-8" }, { "sign_type", _getConfig("signType") }, { "app_cert_sn", _getMerchantCertSN() }, { "alipay_root_cert_sn", _getAlipayRootCertSN() }, }; request_.Protocol = _getConfig("protocol"); request_.Method = "POST"; request_.Pathname = "/gateway.do"; request_.Headers = new Dictionary <string, string>() { { "host", _getConfig("gatewayHost") }, { "content-type", "application/x-www-form-urlencoded;charset=utf-8" }, }; request_.Query = TeaConverter.merge <string>( new Dictionary <string, string>() { { "sign", _sign(systemParams, bizParams, textParams, _getConfig("merchantPrivateKey")) }, }, systemParams ); request_.Body = TeaCore.BytesReadable(_toUrlEncodedRequestBody(bizParams, textParams)); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); Dictionary <string, object> respMap = _readAsJson(response_, method); if (_isCertMode()) { if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap)))) { return(TeaModel.ToObject <AlipayOpenApiGenericResponse>(_toRespModel(respMap))); } } else { if (_verify(respMap, _getConfig("alipayPublicKey"))) { return(TeaModel.ToObject <AlipayOpenApiGenericResponse>(_toRespModel(respMap))); } } throw new TeaException(new Dictionary <string, string>() { { "message", "验签失败,请检查支付宝公钥设置是否正确。" }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
/** * Encapsulate the request and invoke the network * @param action api name * @param protocol http or https * @param method e.g. GET * @param version product version * @param authType when authType is Anonymous, the signature will not be calculate * @param pathname pathname of every api * @param query which contains request params * @param body content of request * @param runtime which controls some details of call api, such as retry times * @return the response */ public async Task <Dictionary <string, object> > DoRequestAsync(string action, string protocol, string method, string version, string authType, Dictionary <string, object> query, Dictionary <string, object> body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "timeouted", "retry" }, { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) }, { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) }, { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) }, { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) }, { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) }, { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) }, { "retry", new Dictionary <string, object> { { "retryable", runtime.Autoretry }, { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) }, } }, { "backoff", new Dictionary <string, object> { { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") }, { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) }, } }, { "ignoreSSL", runtime.IgnoreSSL }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol); request_.Method = method; request_.Pathname = "/"; request_.Query = AlibabaCloud.Commons.Common.Query(TeaConverter.merge <object> ( new Dictionary <string, object>() { { "Action", action }, { "Format", "json" }, { "Timestamp", AlibabaCloud.Commons.Common.GetTimestamp() }, { "Version", version }, { "SignatureNonce", AlibabaCloud.TeaUtil.Common.GetNonce() }, }, query )); // endpoint is setted in product client request_.Headers = new Dictionary <string, string> { { "x-acs-version", version }, { "x-acs-action", action }, { "host", _endpoint }, { "user-agent", GetUserAgent() }, }; if (!AlibabaCloud.TeaUtil.Common.IsUnset(body)) { Dictionary <string, object> tmp = AlibabaCloud.TeaUtil.Common.AnyifyMapValue(AlibabaCloud.Commons.Common.Query(body)); request_.Body = TeaCore.BytesReadable(AlibabaCloud.TeaUtil.Common.ToFormString(tmp)); request_.Headers["content-type"] = "application/x-www-form-urlencoded"; } if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous")) { string accessKeyId = await GetAccessKeyIdAsync(); string accessKeySecret = await GetAccessKeySecretAsync(); string securityToken = await GetSecurityTokenAsync(); if (!AlibabaCloud.TeaUtil.Common.Empty(securityToken)) { request_.Query["SecurityToken"] = securityToken; } request_.Query["SignatureMethod"] = "HMAC-SHA1"; request_.Query["SignatureVersion"] = "1.0"; request_.Query["AccessKeyId"] = accessKeyId; Dictionary <string, string> signedParam = TeaConverter.merge <string> ( request_.Query, AlibabaCloud.Commons.Common.Query(body) ); request_.Query["Signature"] = AlibabaCloud.Commons.Common.GetSignatureV1(signedParam, request_.Method, accessKeySecret); } _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); object obj = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body); Dictionary <string, object> res = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj); if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode)) { throw new TeaException(new Dictionary <string, object> { { "code", Client.DefaultAny(res.Get("Code"), res.Get("code")) + "Error" }, { "message", "code: " + response_.StatusCode + ", " + Client.DefaultAny(res.Get("Message"), res.Get("message")) + " requestid: " + Client.DefaultAny(res.Get("RequestId"), res.Get("requestId")) }, { "data", res }, }); } return(res); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
// testAPI2 comment public async Task TestAPI2Async() { Dictionary <string, bool?> runtime_ = new Dictionary <string, bool?> { // runtime retry comment { "retry", true }, // runtime back comment one // runtime back comment two }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); // new model instance comment Test3 modelInstance = new Test3(); // boolean declare comment bool?bool_ = true; if (bool_) { //empty if } else { //empty else } // api function call comment await TestAPIAsync(); // back comment _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); // empty return comment } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
/** * Encapsulate the request and invoke the network * @param version product version * @param protocol http or https * @param method e.g. GET * @param authType when authType is Anonymous, the signature will not be calculate * @param pathname pathname of every api * @param query which contains request params * @param headers request headers * @param body content of request * @param runtime which controls some details of call api, such as retry times * @return the response */ public async Task <Dictionary <string, object> > DoRequestWithFormAsync(string version, string protocol, string method, string authType, string pathname, Dictionary <string, string> query, Dictionary <string, string> headers, Dictionary <string, object> body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "timeouted", "retry" }, { "readTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ReadTimeout, _readTimeout) }, { "connectTimeout", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.ConnectTimeout, _connectTimeout) }, { "httpProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpProxy, _httpProxy) }, { "httpsProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.HttpsProxy, _httpsProxy) }, { "noProxy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.NoProxy, _noProxy) }, { "maxIdleConns", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxIdleConns, _maxIdleConns) }, { "retry", new Dictionary <string, object> { { "retryable", runtime.Autoretry }, { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) }, } }, { "backoff", new Dictionary <string, object> { { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") }, { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) }, } }, { "ignoreSSL", runtime.IgnoreSSL }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, protocol); request_.Method = method; request_.Pathname = pathname; request_.Headers = TeaConverter.merge <string> ( new Dictionary <string, string>() { { "date", AlibabaCloud.TeaUtil.Common.GetDateUTCString() }, { "host", _endpointHost }, { "accept", "application/json" }, { "x-acs-signature-nonce", AlibabaCloud.TeaUtil.Common.GetNonce() }, { "x-acs-signature-method", "HMAC-SHA1" }, { "x-acs-signature-version", "1.0" }, { "x-acs-version", version }, { "user-agent", AlibabaCloud.TeaUtil.Common.GetUserAgent(_userAgent) }, }, headers ); if (!AlibabaCloud.TeaUtil.Common.IsUnset(body)) { request_.Body = TeaCore.BytesReadable(AlibabaCloud.ROAUtil.Common.ToForm(body)); request_.Headers["content-type"] = "application/x-www-form-urlencoded"; } if (!AlibabaCloud.TeaUtil.Common.IsUnset(query)) { request_.Query = query; } if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous")) { string accessKeyId = await this._credential.GetAccessKeyIdAsync(); string accessKeySecret = await this._credential.GetAccessKeySecretAsync(); string securityToken = await this._credential.GetSecurityTokenAsync(); if (!AlibabaCloud.TeaUtil.Common.Empty(securityToken)) { request_.Headers["x-acs-accesskey-id"] = accessKeyId; request_.Headers["x-acs-security-token"] = securityToken; } string stringToSign = AlibabaCloud.ROAUtil.Common.GetStringToSign(request_); request_.Headers["authorization"] = "acs " + accessKeyId + ":" + AlibabaCloud.ROAUtil.Common.GetSignature(stringToSign, accessKeySecret); } _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); if (AlibabaCloud.TeaUtil.Common.EqualNumber(response_.StatusCode, 204)) { return(new Dictionary <string, object> { { "headers", response_.Headers }, }); } object result = AlibabaCloud.TeaUtil.Common.ReadAsJSON(response_.Body); if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode)) { Dictionary <string, object> err = AlibabaCloud.TeaUtil.Common.AssertAsMap(result); throw new TeaException(new Dictionary <string, object> { { "code", Client.DefaultAny(err.Get("Code"), err.Get("code")) + "Error" }, { "message", "code: " + response_.StatusCode + ", " + Client.DefaultAny(err.Get("Message"), err.Get("message")) + " requestid: " + Client.DefaultAny(err.Get("RequestId"), err.Get("requestId")) }, { "data", err }, }); } return(new Dictionary <string, object> { { "headers", response_.Headers }, { "body", result }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
public async Task <AlipayOfflineMaterialImageUploadResponse> UploadAsync(string imageName, string imageFilePath) { Dictionary <string, object> runtime_ = new Dictionary <string, object>() { { "connectTimeout", 100000 }, { "readTimeout", 100000 }, { "retry", new Dictionary <string, int?>() { { "maxAttempts", 0 }, } }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); Dictionary <string, string> systemParams = new Dictionary <string, string>() { { "method", "alipay.offline.material.image.upload" }, { "app_id", _getConfig("appId") }, { "timestamp", _getTimestamp() }, { "format", "json" }, { "version", "1.0" }, { "alipay_sdk", _getSdkVersion() }, { "charset", "UTF-8" }, { "sign_type", _getConfig("signType") }, { "app_cert_sn", _getMerchantCertSN() }, { "alipay_root_cert_sn", _getAlipayRootCertSN() }, }; Dictionary <string, object> bizParams = new Dictionary <string, object>() { }; Dictionary <string, string> textParams = new Dictionary <string, string>() { { "image_type", "jpg" }, { "image_name", imageName }, }; Dictionary <string, string> fileParams = new Dictionary <string, string>() { { "image_content", imageFilePath }, }; string boundary = _getRandomBoundary(); request_.Protocol = _getConfig("protocol"); request_.Method = "POST"; request_.Pathname = "/gateway.do"; request_.Headers = new Dictionary <string, string>() { { "host", _getConfig("gatewayHost") }, { "content-type", _concatStr("multipart/form-data;charset=utf-8;boundary=", boundary) }, }; request_.Query = TeaConverter.merge <string>( new Dictionary <string, string>() { { "sign", _sign(systemParams, bizParams, textParams, _getConfig("merchantPrivateKey")) }, }, systemParams ); request_.Body = _toMultipartRequestBody(textParams, fileParams, boundary); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); Dictionary <string, object> respMap = _readAsJson(response_, "alipay.offline.material.image.upload"); if (_isCertMode()) { if (_verify(respMap, _extractAlipayPublicKey(_getAlipayCertSN(respMap)))) { return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(_toRespModel(respMap))); } } else { if (_verify(respMap, _getConfig("alipayPublicKey"))) { return(TeaModel.ToObject <AlipayOfflineMaterialImageUploadResponse>(_toRespModel(respMap))); } } throw new TeaException(new Dictionary <string, string>() { { "message", "验签失败,请检查支付宝公钥设置是否正确。" }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
public async Task TestDoActionAsync() { TeaRequest teaRequest = new TeaRequest(); teaRequest.Protocol = "https"; teaRequest.Method = "GET"; teaRequest.Headers = new Dictionary <string, string>(); teaRequest.Headers["host"] = "www.alibabacloud.com"; teaRequest.Pathname = "/s/zh"; teaRequest.Query = new Dictionary <string, string>(); teaRequest.Query.Add("k", "ecs"); TeaResponse teaResponse = await TeaCore.DoActionAsync(teaRequest); Assert.NotNull(teaResponse); Dictionary <string, object> runtime = new Dictionary <string, object>(); runtime.Add("readTimeout", 4000); runtime.Add("connectTimeout", 0); teaResponse = await TeaCore.DoActionAsync(teaRequest, runtime); Assert.NotNull(teaResponse); string bodyStr = TeaCore.GetResponseBody(teaResponse); Assert.NotNull(bodyStr); teaRequest.Method = "POST"; teaRequest.Body = new MemoryStream(Encoding.UTF8.GetBytes("test")); teaResponse = await TeaCore.DoActionAsync(teaRequest, runtime); Assert.NotNull(teaResponse); TeaRequest teaRequest404 = new TeaRequest(); teaRequest404.Protocol = "https"; teaRequest404.Method = "GET"; teaRequest404.Headers = new Dictionary <string, string>(); teaRequest404.Headers["host"] = "www.alibabacloud404.com"; teaRequest404.Pathname = "/s/zh"; teaRequest404.Query = new Dictionary <string, string>(); teaRequest404.Query.Add("k", "ecs"); Dictionary <string, object> runtime404 = new Dictionary <string, object>(); runtime404.Add("readTimeout", 7000); runtime404.Add("connectTimeout", 7000); await Assert.ThrowsAsync <HttpRequestException>(async() => { await TeaCore.DoActionAsync(teaRequest404, runtime); }); TeaRequest requestException = new TeaRequest { Protocol = "http", Method = "GET", Pathname = "/test" }; Dictionary <string, object> runtimeException = new Dictionary <string, object>(); requestException.Headers["host"] = "www.aliyun.com"; TeaResponse responseException = await TeaCore.DoActionAsync(requestException, runtimeException); }
public async Task <Darabonba.import.Models.RuntimeObject> Complex1Async(ComplexRequest request, Darabonba.import.Client client) { request.Validate(); client.Validate(); Dictionary <string, string> runtime_ = new Dictionary <string, string> { { "timeouted", "retry" }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); string name = "complex"; Dictionary <string, string> mapVal = new Dictionary <string, string> { { "test", "ok" }, }; request_.Protocol = _endpointMap.Get(_protocol); request_.Port = request.Num; request_.Method = "GET"; request_.Pathname = "/" + _pathname; request_.Query = new Dictionary <string, string> { { "date", "2019" }, }; _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); if (true && true) { return(null); } else if (true || false) { return(new Darabonba.import.Models.RuntimeObject()); } client.Print(request.ToMap(), "1"); await HelloAsync(request.ToMap(), new List <string> { "1", "2" }); await HelloAsync(null, null); return(TeaModel.ToObject <Darabonba.import.Models.RuntimeObject>(new Dictionary <string, object>() { })); await Complex3Async(null); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }
public async Task <Dictionary <string, object> > _requestAsync(string method, string pathname, Dictionary <string, object> query, Dictionary <string, string> headers, object body, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime) { Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "timeouted", "retry" }, { "readTimeout", runtime.ReadTimeout }, { "connectTimeout", runtime.ConnectTimeout }, { "httpProxy", runtime.HttpProxy }, { "httpsProxy", runtime.HttpsProxy }, { "noProxy", runtime.NoProxy }, { "maxIdleConns", runtime.MaxIdleConns }, { "retry", new Dictionary <string, object> { { "retryable", runtime.Autoretry }, { "maxAttempts", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.MaxAttempts, 3) }, } }, { "backoff", new Dictionary <string, object> { { "policy", AlibabaCloud.TeaUtil.Common.DefaultString(runtime.BackoffPolicy, "no") }, { "period", AlibabaCloud.TeaUtil.Common.DefaultNumber(runtime.BackoffPeriod, 1) }, } }, { "ignoreSSL", runtime.IgnoreSSL }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); string accesskeyId = await GetAccessKeyIdAsync(); string accessKeySecret = await GetAccessKeySecretAsync(); request_.Protocol = AlibabaCloud.TeaUtil.Common.DefaultString(_protocol, "HTTP"); request_.Method = method; request_.Pathname = pathname; request_.Headers = TeaConverter.merge <string> ( new Dictionary <string, string>() { { "user-agent", GetUserAgent() }, { "Date", AlibabaCloud.OpenSearchUtil.Common.GetDate() }, { "host", AlibabaCloud.TeaUtil.Common.DefaultString(_endpoint, "opensearch-cn-hangzhou.aliyuncs.com") }, { "X-Opensearch-Nonce", AlibabaCloud.TeaUtil.Common.GetNonce() }, }, headers ); if (!AlibabaCloud.TeaUtil.Common.IsUnset(query)) { request_.Query = AlibabaCloud.TeaUtil.Common.StringifyMapValue(query); } if (!AlibabaCloud.TeaUtil.Common.IsUnset(body)) { string reqBody = AlibabaCloud.TeaUtil.Common.ToJSONString(body); request_.Headers["Content-MD5"] = AlibabaCloud.OpenSearchUtil.Common.GetContentMD5(reqBody); request_.Headers["Content-Type"] = "application/json"; request_.Body = TeaCore.BytesReadable(reqBody); } request_.Headers["Authorization"] = AlibabaCloud.OpenSearchUtil.Common.GetSignature(request_, accesskeyId, accessKeySecret); _lastRequest = request_; TeaResponse response_ = await TeaCore.DoActionAsync(request_, runtime_); string objStr = AlibabaCloud.TeaUtil.Common.ReadAsString(response_.Body); if (AlibabaCloud.TeaUtil.Common.Is4xx(response_.StatusCode) || AlibabaCloud.TeaUtil.Common.Is5xx(response_.StatusCode)) { throw new TeaException(new Dictionary <string, object> { { "message", response_.StatusMessage }, { "data", objStr }, { "code", response_.StatusCode }, }); } object obj = AlibabaCloud.TeaUtil.Common.ParseJSON(objStr); Dictionary <string, object> res = AlibabaCloud.TeaUtil.Common.AssertAsMap(obj); return(new Dictionary <string, object> { { "body", res }, { "headers", response_.Headers }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }