コード例 #1
0
ファイル: Rest.cs プロジェクト: wildbunny/metaexchange
        static public Task <string> ExecuteGetAsync(string url, int timeoutMillis = 20000)
        {
            WebClientTimeout client = new WebClientTimeout(timeoutMillis);

            client.Encoding = System.Text.Encoding.UTF8;
            return(client.DownloadStringTaskAsync(url));
        }
コード例 #2
0
ファイル: Rest.cs プロジェクト: wildbunny/metaexchange
        static public string ExecutePostSync(string url, string query, string contentType = kContentTypeForm,
                                             string username = null, string password = null)
        {
            WebClientTimeout client = new WebClientTimeout(m_gTimeoutSeconds * 1000);

            client.Encoding = System.Text.Encoding.UTF8;
            if (username != null)
            {
                client.Credentials = new NetworkCredential(username, password);
            }
            client.Headers[HttpRequestHeader.ContentType] = contentType;

            try
            {
                return(client.UploadString(url, query));
            }
            catch (WebException e)
            {
                if (e.Response != null && e.Response.ContentLength > 0)
                {
                    return(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: Rest.cs プロジェクト: wildbunny/metaexchange
        static public WebClientTimeout ConfigurePost(string url, string query, string contentType = kContentTypeForm, int timeoutMillis = 5000)
        {
            WebClientTimeout client = new WebClientTimeout(timeoutMillis);

            client.Encoding = System.Text.Encoding.UTF8;
            client.Headers[HttpRequestHeader.ContentType] = contentType;
            return(client);
        }