ToParameterString() public method

public ToParameterString ( ) : string
return string
Beispiel #1
0
        private Result Post(string path, Parameters parameters, bool ssl)
        {
            try {
                if (Config.SkipSslValidation) {
                    ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {	return true; };
                }

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create (Config.GetUrl (path, ssl));

                request.Method = "POST";
                request.ContentType = FORM_URL_ENCODED;
                request.ServicePoint.Expect100Continue = false;

                if (parameters != null) {
                    string data = parameters.ToParameterString ();
                    if (data.Length > 0) {
                        if (Config.UTF8Encode) {
                            UTF8Encoding encoding = new UTF8Encoding ();
                            byte[] bytes = encoding.GetBytes (data);
                            request.ContentLength = bytes.Length;

                            Stream stream = request.GetRequestStream ();
                            stream.Write (bytes, 0, bytes.Length);
                            stream.Close ();
                        } else {
                            request.ContentLength = data.Length;
                            StreamWriter writer = new StreamWriter (request.GetRequestStream (), Encoding.ASCII);
                            writer.Write (data);
                            writer.Close ();
                        }
                    }
                } else {
                    request.ContentLength = 0;
                }

                HttpWebResponse response = (HttpWebResponse)(request.GetResponse ());

                return new Result (response);
            } catch (WebException webex) {
                return new Result (webex.Response);
            } catch (Exception ex) {
                Console.WriteLine (ex.Message);
                Console.WriteLine (ex.StackTrace);
                return new Result (ex);
            } finally {
                if (Config.SkipSslValidation) {
                    ServicePointManager.ServerCertificateValidationCallback -= delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {	return true; };
                }
            }
        }
Beispiel #2
0
 public string GetUrl(string path, bool ssl, Parameters parameters)
 {
     return String.Format ("http{0}://{1}/{2}?{3}", ssl ? "s" : "", ApiEndPoint, path, parameters.ToParameterString ());
 }