本文整理汇总了C#中Method.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Method.ToString方法的具体用法?C# Method.ToString怎么用?C# Method.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generic
public string Generic(string relativeUrl, Method method, NameValueCollection requestParameters = null)
{
var apiUrl = string.Format("https://api.quickpay.net{0}", relativeUrl);
var request = (HttpWebRequest)WebRequest.Create(apiUrl);
request.Method = method.ToString();
request.Accept = "application/json";
request.Headers.Add("Authorization", BasicAuthToken(apiKey));
request.Headers.Add("Accept-Version", "v10");
if (requestParameters != null) {
var postData = requestParameters.AllKeys.Aggregate("",
(current, key) => current + (key + "=" + HttpUtility.UrlEncode(requestParameters[key]) + "&"))
.TrimEnd('&');
request.ContentLength = postData.Length;
request.ContentType = "application/x-www-form-urlencoded";
using (var writer = new StreamWriter(request.GetRequestStream())) {
writer.Write(postData);
}
}
var response = (HttpWebResponse)request.GetResponse();
var sr = new StreamReader(response.GetResponseStream());
var responseContent = sr.ReadToEnd();
return responseContent;
}
示例2: WebRequest
public string WebRequest(Method method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter writer = null;
string str = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
webRequest.UserAgent = "[You user agent]";
webRequest.Timeout = 0x4e20;
if (method == Method.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
writer = new StreamWriter(webRequest.GetRequestStream());
try
{
writer.Write(postData);
}
catch
{
throw;
}
finally
{
writer.Close();
writer = null;
}
}
str = this.WebResponseGet(webRequest);
webRequest = null;
return str;
}
示例3: AddMethodNode
private Node AddMethodNode(Method method, Node node)
{
var n = new Node();
n.Name = method.ToString().ToLower();
n.Type = NodeType.Static;
n.Parent = node;
node.Children.Add(n);
return n;
}
示例4: RequestData
public RequestData(Method method, string wsKey)
{
this.method = method.ToString();
this.parameters = new Dictionary<string, object>();
Dictionary<string, object> _header = new Dictionary<string, object>();
_header.Add("wsKey", wsKey);
this.header = _header;
}
示例5: PostData
public string PostData(Method method, object PostData, string targetUrl , string ContentType = "application/x-www-form-urlencoded", int CodePage = 65001)
{
if (string.IsNullOrEmpty(targetUrl)) throw new ArgumentException("目標位置網址不可為空或 NULL");
string postString = ObjectParserHelper.ObjectToPostString(PostData);
if (method == Method.GET || method == Method.DELETE)
{
targetUrl = string.Format("{0}?{1}", targetUrl, postString);
}
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(targetUrl);
webRequest.Method = method.ToString();
webRequest.AllowAutoRedirect = false;
if (!string.IsNullOrEmpty(ContentType))
{
webRequest.ContentType = ContentType;
}
//SSL不對也不管
ServicePointManager.ServerCertificateValidationCallback +=
(object s, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
{ return true; };
if (!String.IsNullOrEmpty(postString) && (method == Method.POST || method == Method.PUT))
{
var parameterString = Encoding.GetEncoding(CodePage).GetBytes(postString);
webRequest.ContentLength = parameterString.Length;
using (var buffer = webRequest.GetRequestStream())
{
buffer.Write(parameterString, 0, parameterString.Length);
buffer.Close();
}
}
HttpWebResponse webResponse;
string JsonResponse;
try
{
webResponse = (HttpWebResponse)webRequest.GetResponse();
}
catch (WebException ex)
{
throw new WebException(string.Format("連線到{0} 發生錯誤:{1}", targetUrl, ex.Message), ex.InnerException, ex.Status, ex.Response);
}
using (var streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding(CodePage)))
{
JsonResponse = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
}
return JsonResponse;
}
示例6: HttpRequestMethod
public static string HttpRequestMethod(Method method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
//webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
webRequest.Timeout = 120000;
if (method == Method.POST)
{
byte[] byteData = UTF8Encoding.UTF8.GetBytes(postData);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteData.Length;
//webRequest.Headers.Add("APIKEY", APIKey);
//POST the data.
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch (Exception ex)
{
string strError = ex.Message;
}
finally
{
requestWriter.Close();
requestWriter = null;
}
}
else
{
}
responseData = WebResponseGet(webRequest);
webRequest = null;
return responseData;
}
示例7: WebRequest
/// <summary>
/// Web Request Wrapper
/// </summary>
/// <param name="method">Http Method</param>
/// <param name="url">Full url to the web resource</param>
/// <param name="postData">Data to post in querystring format</param>
/// <param name="headers">Additional Header Data</param>
/// <returns>The web server response.</returns>
public static string WebRequest(Method method, string url, string postData, List<KeyValuePair<string, string>> headers)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
if (headers != null)
{
foreach (KeyValuePair<string, string> header in headers)
{
webRequest.Headers.Add(header.Key, header.Value);
}
}
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
//webRequest.UserAgent = "Identify your application please.";
//webRequest.Timeout = 20000;
if (method == Method.POST || method == Method.DELETE)
{
byte[] bytes = Encoding.UTF8.GetBytes(postData);
webRequest.ContentType = "application/x-www-form-urlencoded";
//webRequest.ContentType = "application/json";
webRequest.ContentLength = bytes.Length;
//POST the data.
using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(postData);
requestWriter.Close();
}
}
responseData = WebResponseGet(webRequest);
webRequest = null;
return responseData;
}
示例8: WebRequest
public string WebRequest(Method method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
webRequest.UserAgent = "[You user agent]";
webRequest.Timeout = 20000;
if (method == Method.POST || method == Method.PUT)
{
//webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentType = "application/json";
//POST the data.
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch
{
throw;
}
finally
{
requestWriter.Close();
requestWriter = null;
}
}
responseData = WebResponseGet(webRequest);
webRequest = null;
return responseData;
}
示例9: request
private static HttpStatusCode request(Uri uri, Method method, string body)
{
var w = (HttpWebRequest)WebRequest.Create(uri);
w.Proxy = null;
w.Method = method.ToString();
w.ContentType = "application/json";
if (!string.IsNullOrEmpty(body))
{
var dataStream = w.GetRequestStream();
byte[] b = Encoding.UTF8.GetBytes(body);
dataStream.Write(b, 0, b.Length);
dataStream.Close();
}
HttpStatusCode statusCode;
try
{
var resp = w.GetResponse();
resp.Close();
statusCode = ((HttpWebResponse) resp).StatusCode;
}
catch (WebException ex)
{
var webResponse = ex.Response;
webResponse.Close();
statusCode = ((HttpWebResponse)webResponse).StatusCode;
}
return statusCode;
}
示例10: WebRequest
/// <summary>
/// Web Request Wrapper
/// </summary>
/// <param name="method">
/// Http Method
/// </param>
/// <param name="url">
/// Full url to the web resource
/// </param>
/// <param name="postData">
/// Data to post in querystring format
/// </param>
/// <returns>
/// The web server response.
/// </returns>
public string WebRequest(Method method, string url, string postData)
{
HttpWebRequest webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
// webRequest.UserAgent = "Identify your application please.";
// webRequest.Timeout = 20000;
if (method == Method.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
// POST the data.
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
finally
{
requestWriter.Close();
}
}
string responseData = this.WebResponseGet(webRequest);
return responseData;
}
示例11: OAuthWebRequest
/// <summary>
/// Submit a web request using oAuth.
/// </summary>
/// <param name="method">
/// GET or POST
/// </param>
/// <param name="url">
/// The full url, including the querystring.
/// </param>
/// <param name="postData">
/// Data to post (querystring format)
/// </param>
/// <returns>
/// The web server response.
/// </returns>
public string OAuthWebRequest(Method method, string url, string postData)
{
string outUrl;
string querystring;
// Setup postData for signing.
// Add the postData to the querystring.
if (method == Method.POST)
{
if (postData.Length > 0)
{
// Decode the parameters and re-encode using the oAuth UrlEncode method.
NameValueCollection qs = HttpUtility.ParseQueryString(postData);
postData = string.Empty;
foreach (string key in qs.AllKeys)
{
if (postData.Length > 0)
{
postData += "&";
}
qs[key] = HttpUtility.UrlDecode(qs[key]);
qs[key] = this.UrlEncode(qs[key]);
postData += key + "=" + qs[key];
}
if (url.IndexOf("?") > 0)
{
url += "&";
}
else
{
url += "?";
}
url += postData;
}
}
else if (method == Method.GET && !string.IsNullOrEmpty(postData))
{
url += "?" + postData;
}
Uri uri = new Uri(url);
string nonce = this.GenerateNonce();
string timeStamp = this.GenerateTimeStamp();
// Generate Signature
string sig = this.GenerateSignature(
uri,
this.ConsumerKey,
this.ConsumerSecret,
this.Token,
this.TokenSecret,
this.CallBackUrl,
method.ToString(),
timeStamp,
nonce,
this.PIN,
out outUrl,
out querystring);
querystring += "&oauth_signature=" + HttpUtility.UrlEncode(sig);
// Convert the querystring to postData
if (method == Method.POST)
{
postData = querystring;
querystring = string.Empty;
}
if (querystring.Length > 0)
{
outUrl += "?";
}
string ret = this.WebRequest(method, outUrl + querystring, postData);
return ret;
}
示例12: oAuthWebRequest
/// <summary>
/// Submit a web request using oAuth.
/// </summary>
/// <param name="method">GET or POST</param>
/// <param name="url">The full url, including the querystring.</param>
/// <param name="postData">Data to post (querystring format)</param>
/// <returns>The web server response.</returns>
public string oAuthWebRequest(Method method, string resourceUrl, SortedDictionary<string, string> requestParameters)
{
string resultString = string.Empty;
try
{
ServicePointManager.Expect100Continue = false;
HttpWebRequest request = null;
if (method == Method.POST)
{
var postBody = requestParameters.ToWebString();
request = (HttpWebRequest)WebRequest.Create(resourceUrl);
request.Method = method.ToString();
//if (resourceUrl == Globals.StatusUpdateUrl)
//{
// request.ContentType = "multipart/form-data; type=\"image/jpeg\"; start=\"<media>\";boundary=\"--0246824681357ACXZabcxyz\"";
//}
request.ContentType = "application/x-www-form-urlencoded";
request.ProtocolVersion = HttpVersion.Version11;
using (var stream = request.GetRequestStream())
{
byte[] content = Encoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
}
else if (method == Method.GET)
{
request = (HttpWebRequest)WebRequest.Create(resourceUrl + "?"
+ requestParameters.ToWebString());
request.Method = method.ToString();
}
else
{
//other verbs can be addressed here...
}
if (request != null)
{
var authHeader = CreateHeader(resourceUrl, method, requestParameters);
request.Headers.Add("Authorization", authHeader);
var response = request.GetResponse();
using (var sd = new StreamReader(response.GetResponseStream()))
{
resultString = sd.ReadToEnd();
response.Close();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error : " + ex.StackTrace);
}
return resultString;
}
示例13: oAuthWebRequest
/// <summary>
/// Submit a web request using oAuth.
/// </summary>
/// <param name="method">GET or POST</param>
/// <param name="url">The full url, including the querystring.</param>
/// <param name="postData">Data to post (querystring format)</param>
/// <returns>The web server response.</returns>
public string oAuthWebRequest(Method method, string url, string postData)
{
string outUrl = "";
string querystring = "";
string ret = "";
//Setup postData for signing.
//Add the postData to the querystring.
if (method == Method.POST)
{
if (postData.Length > 0)
{
//Decode the parameters and re-encode using the oAuth UrlEncode method.
NameValueCollection qs = HttpUtility.ParseQueryString(postData);
postData = "";
foreach (string key in qs.AllKeys)
{
if (postData.Length > 0)
{
postData += "&";
}
qs[key] = HttpUtility.UrlDecode(qs[key]);
qs[key] = UrlEncode(qs[key]);
postData += key + "=" + qs[key];
}
if (url.IndexOf("?", StringComparison.Ordinal) > 0)
{
url += "&";
}
else
{
url += "?";
}
url += postData;
}
}
var uri = new Uri(url);
string nonce = this.GenerateNonce();
string timeStamp = this.GenerateTimeStamp();
//Generate Signature
string sig = GenerateSignature(uri,
this.ConsumerKey,
this.ConsumerSecret,
this.Token,
this.TokenSecret,
this.Verifier,
method.ToString(),
timeStamp,
nonce,
out outUrl,
out querystring);
querystring += "&oauth_signature=" + HttpUtility.UrlEncode(sig);
//Convert the querystring to postData
if (method == Method.POST)
{
postData = querystring;
querystring = "";
}
if (querystring.Length > 0)
{
outUrl += "?";
}
ret = WebRequest(method, outUrl + querystring, postData);
return ret;
}
示例14: GetMethodStatement
public static string GetMethodStatement(Method method)
{
if (method.IsConstructor)
return "global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject({1});";
var type = method.ReturnType;
var typeName = method.Return;
if (typeName == "void")
return "@__env.Call{0}VoidMethod({1});";
switch (typeName)
{
case "bool":
return "return @__env.Call{0}BooleanMethod({1});";
case "int":
return "return @__env.Call{0}IntMethod({1});";
case "double":
return "return @__env.Call{0}DoubleMethod({1});";
case "float":
return "return @__env.Call{0}FloatMethod({1});";
case "short":
return "return @__env.Call{0}ShortMethod({1});";
case "long":
return "return @__env.Call{0}LongMethod({1});";
case "char":
return "return @__env.Call{0}CharMethod({1});";
case "byte":
return "return @__env.Call{0}ByteMethod({1});";
}
StringBuilder ret = new StringBuilder();
/*
if (typeName.EndsWith("[]"))
{
// TODO: Actually return something
ret.Append("return null;//");
}
else
{
if (typeName == "java.lang.Object" || (type != null && type.IsInterface))
{
ret.AppendFormat("return global::net.sf.jni4net.utils.Convertor.FullJ2C<{0}>", typeName);
}
else
{
ret.AppendFormat("return global::net.sf.jni4net.utils.Convertor.StrongJ2Cp<{0}>", typeName);
}
}
*/
if (method.Return == null)
Console.WriteLine(method.ToString() + "::" + method.Type);
if (method.Return.EndsWith("[]"))
ret.AppendFormat("return global::MonoJavaBridge.JavaBridge.WrapJavaArrayObject<{0}>", method.Return.Substring(0, method.Return.Length - 2));
else if (method.ReturnType.IsInterface)
ret.AppendFormat("return global::MonoJavaBridge.JavaBridge.WrapIJavaObject<global::{0}>", method.Return);
else
ret.Append("return global::MonoJavaBridge.JavaBridge.WrapJavaObject");
//ret.AppendFormat("(typeof({0}), ", method.Return);
ret.Append("(@__env.Call{0}ObjectMethod({1}))");
ret.AppendFormat(" as {0};", method.Return);
return ret.ToString();
}
示例15: GetResponse
private string GetResponse(string resourceUrl, Method method, SortedDictionary requestParameters)
{
ServicePointManager.Expect100Continue = false;
WebRequest request = null;
string resultString = string.Empty;
if (method == Method.POST)
{
var postBody = requestParameters.ToWebString();
request = (HttpWebRequest)WebRequest.Create(resourceUrl);
request.Method = method.ToString();
request.ContentType = "application/x-www-form-urlencoded";
using (var stream = request.GetRequestStream())
{
byte[] content = Encoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
}
else if (method == Method.GET)
{
request = (HttpWebRequest)WebRequest.Create(resourceUrl + "?" + requestParameters.ToWebString());
request.Method = method.ToString();
}
else
{
//other verbs can be addressed here...
}
if (request != null)
{
var authHeader = CreateHeader(resourceUrl, method, requestParameters);
request.Headers.Add("Authorization", authHeader);
var response = request.GetResponse();
using (var sd = new StreamReader(response.GetResponseStream()))
{
resultString = sd.ReadToEnd(); response.Close();
}
}
return resultString;
}