本文整理汇总了C#中MethodType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MethodType.ToString方法的具体用法?C# MethodType.ToString怎么用?C# MethodType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodType
的用法示例。
在下文中一共展示了MethodType.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Request
public static void Request(MethodType method, string uri, string body, CallBack<string> callBack)
{
try
{
Init("8aa5b8b5-f769-11e3-954e-06a6fa0000b9", "6ef2e5c0-3ef1-11e4-ae91-06a6fa0000b9");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(APIEndpoint + uri);
request.Method = method.ToString();
request.ContentType = "applications/json";
if (PlayerPrefs.HasKey("access_token"))
request.Headers["Authorization"] = "Bearer " + PlayerPrefs.GetString("access_token");
if(request.Method == "POST" || request.Method == "PUT")
{
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(body);
writer.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
callBack(responseFromServer);
}
catch(Exception e)
{
Debug.Log(e.Message);
}
}
示例2: CreateWebRequest
private WebRequest CreateWebRequest(MethodType methodType)
{
Enforce.NotNullOrEmpty(Url);
string requestUrl = (methodType == MethodType.Get && Parameters.Count > 0)
? Url + "?" + Parameters.ToQueryParameter()
: Url;
var req = WebRequest.CreateHttp(requestUrl);
req.Headers[HttpRequestHeader.Authorization] = GetAuthorizationHeader(methodType);
req.Headers["X-User-Agent"] = AppBootstrapper.UserAgentVersion;
req.Method = methodType.ToString().ToUpper();
if (methodType == MethodType.Post)
req.ContentType = "application/x-www-form-urlencoded";
return req;
}
示例3: GenerateSignature
private string GenerateSignature(Uri uri, MethodType methodType, Token token, IEnumerable<KeyValuePair<string, object>> parameters)
{
var hmacKeyBase = ConsumerSecret.UrlEncode() + "&" + ((token == null) ? "" : token.Secret).UrlEncode();
using (var hmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(hmacKeyBase)))
{
var stringParameter = parameters.OrderBy(p => p.Key)
.ThenBy(p => p.Value)
.ToQueryParameter();
var signatureBase = methodType.ToString().ToUpper() +
"&" + uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped).UrlEncode() +
"&" + stringParameter.UrlEncode();
var hash = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(signatureBase));
return Convert.ToBase64String(hash).UrlEncode();
}
}
示例4: ComposeStringToSign
public string ComposeStringToSign(MethodType? method, string uriPattern, ISigner signer,
Dictionary<string, string> queries, Dictionary<string, string> headers, Dictionary<string, string> paths)
{
var sortedDictionary = SortDictionary(queries);
StringBuilder canonicalizedQueryString = new StringBuilder();
foreach (var p in sortedDictionary)
{
canonicalizedQueryString.Append("&")
.Append(AcsURLEncoder.PercentEncode(p.Key)).Append("=")
.Append(AcsURLEncoder.PercentEncode(p.Value));
}
StringBuilder stringToSign = new StringBuilder();
stringToSign.Append(method.ToString());
stringToSign.Append(SEPARATOR);
stringToSign.Append(AcsURLEncoder.PercentEncode("/"));
stringToSign.Append(SEPARATOR);
stringToSign.Append(AcsURLEncoder.PercentEncode(
canonicalizedQueryString.ToString().Substring(1)));
return stringToSign.ToString();
}
示例5: GenerateSignature
/// <summary>
/// Generates the signature.
/// </summary>
/// <param name="t">The tokens.</param>
/// <param name="httpMethod">The HTTP method.</param>
/// <param name="url">The URL.</param>
/// <param name="prm">The parameters.</param>
/// <returns>The signature.</returns>
internal static string GenerateSignature(Tokens t, MethodType httpMethod, Uri url, IEnumerable<KeyValuePair<string, string>> prm)
{
var key = Encoding.UTF8.GetBytes(
string.Format("{0}&{1}", UrlEncode(t.ConsumerSecret),
UrlEncode(t.AccessTokenSecret)));
var prmstr = prm.Select(x => new KeyValuePair<string, string>(UrlEncode(x.Key), UrlEncode(x.Value)))
.Concat(
url.Query.TrimStart('?').Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x =>
{
var s = x.Split('=');
return new KeyValuePair<string, string>(s[0], s[1]);
})
)
.OrderBy(x => x.Key).ThenBy(x => x.Value)
.Select(x => x.Key + "=" + x.Value)
.JoinToString("&");
var msg = Encoding.UTF8.GetBytes(
string.Format("{0}&{1}&{2}",
httpMethod.ToString().ToUpperInvariant(),
UrlEncode(url.GetComponents(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped)),
UrlEncode(prmstr)
));
return Convert.ToBase64String(SecurityUtils.HmacSha1(key, msg));
}
示例6: CallRestService
public string CallRestService(string methodUrl, string requestBody, MethodType methodType, string contentType = "application/json; charset=utf-8")
{
StringBuilder returnValue = null;
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream resStream = null;
try
{
request = (HttpWebRequest)WebRequest.Create(BaseUrl + methodUrl);
request.Method = methodType.ToString();
if (CustomHeaders != null)
request.Headers.Add(CustomHeaders);
if (methodType == MethodType.POST)
{
request.ContentType = contentType;
byte[] byteData = UTF8Encoding.UTF8.GetBytes(requestBody);
request.ContentLength = byteData.Length;
using (Stream sw = request.GetRequestStream())
{
if (byteData.Length > 0)
sw.Write(byteData, 0, byteData.Length);
}
}
request.Timeout = _timeout;
response = (HttpWebResponse)request.GetResponse();
resStream = response.GetResponseStream();
returnValue = new StringBuilder();
if (resStream != null && resStream.CanRead)
{
using (var sr = new StreamReader(resStream))
{
const int bufferSize = 4096;
var buffer = new char[bufferSize];
int byteCount = sr.Read(buffer, 0, buffer.Length);
while (byteCount > 0)
{
returnValue.Append(new string(buffer, 0, byteCount));
byteCount = sr.Read(buffer, 0, buffer.Length);
}
}
}
}
catch (Exception)
{
throw;
}
finally
{
if (response != null)
{
response.Close();
}
if (resStream != null)
{
resStream.Close();
resStream.Dispose();
}
}
return returnValue.ToString();
}
示例7: RunMethod
private void RunMethod(Process p, Activity a, MethodType type)
{
//Do a quick check
switch (type)
{
case MethodType.PreMethod:
if (!a.PreMethodCall.NeedToInvoke) return;
break;
case MethodType.PostMethod:
if (!a.PostMethodCall.NeedToInvoke) return;
break;
}
string sAssembly = (type == MethodType.PreMethod) ? a.PreMethodCall.Assembly : a.PostMethodCall.Assembly;
string sClass = (type == MethodType.PreMethod) ? a.PreMethodCall.Class : a.PostMethodCall.Class;
string sMethod = (type == MethodType.PreMethod) ? a.PreMethodCall.Method : a.PostMethodCall.Method;
List<string> sParameters = (type == MethodType.PreMethod) ? a.PreMethodCall.Parameters : a.PostMethodCall.Parameters;
//Run method.
try
{
InvokeMethod(p, a, sAssembly, sClass, sMethod, sParameters);
SendResult(new TestResultArgs(p, a, (type == MethodType.PreMethod) ? TestResultStage.ActivityPreMethodExecuted : TestResultStage.ActivityPostMethodExecuted));
}
catch (Exception ex)
{
if (ex.IsFatal())
{
throw;
}
//TODO: refactor to use FailTest
p.ActivityExecutionError = a.ActivityExecutionError = ex.Message.ToString();
SendResult(new TestResultArgs(p, a, TestResultStage.ActivityExecutionError, type.ToString() + " execution error : " + p.ActivityExecutionError));
p.ProcessHasUnexpectedErrors = true;
}
}
示例8: Preprocessing
/// <summary>
/// Processing request data before action
/// </summary>
/// <param name="request"></param>
/// <param name="methodType"></param>
/// <returns></returns>
private static CleantalkRequest Preprocessing(CleantalkRequest request, MethodType methodType)
{
if (string.IsNullOrWhiteSpace(request.AuthKey))
{
throw new ArgumentNullException("AuthKey is empty");
}
switch (methodType)
{
case MethodType.check_message:
//nothing to do
break;
case MethodType.check_newuser:
if (string.IsNullOrWhiteSpace(request.SenderNickname))
{
throw new ArgumentNullException("SenderNickname is empty");
}
if (string.IsNullOrWhiteSpace(request.SenderEmail))
{
throw new ArgumentNullException("SenderEmail is empty");
}
break;
case MethodType.send_feedback:
if (string.IsNullOrWhiteSpace(request.Feedback))
{
throw new ArgumentNullException("Feedback is empty");
}
break;
default:
throw new ArgumentOutOfRangeException("methodType", methodType, null);
}
request.MethodName = methodType.ToString();
return request;
}