Beispiel #1
0
    /// <summary>
    /// 获得相应数据
    /// </summary>
    /// <param name="requestUrl"></param>
    /// <param name="method"></param>
    /// <param name="timeStr"></param>
    /// <param name="auth"></param>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string GetResponseData(Uri url, string method, string timeStr, string auth, byte[] param)
    {
        if (url == null)
        {
            return(HelperTool.Json(false, "url参数不能空"));
        }
        if (string.IsNullOrWhiteSpace(method))
        {
            return(HelperTool.Json(false, "method"));
        }
        if (string.IsNullOrWhiteSpace(timeStr))
        {
            return(HelperTool.Json(false, "time参数不能空"));
        }
        if (string.IsNullOrWhiteSpace(auth))
        {
            return(HelperTool.Json(false, "auth参数不能空"));
        }

        var _client = new WebClient();

        _client.Headers.Set("accept-encoding", "gzip, deflate");
        _client.Headers.Set("host", url.Host);
        _client.Headers.Set("content-type", "application/json; charset=utf-8");
        _client.Headers.Set("x-bce-date", timeStr);
        _client.Headers.Set(HttpRequestHeader.Authorization, auth);
        _client.Headers.Set("accept", "*/*");

        try
        {
            byte[] _responseData = _client.UploadData(url, method, param);
            return(System.Text.Encoding.UTF8.GetString(_responseData));//解码
        }
        catch (WebException ex)
        {
            throw ex;
        }
    }