コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            var    keywords     = context.Request.QueryString["k"];
            string responseJson = string.Empty;

            if (string.IsNullOrEmpty(keywords))
            {
                responseJson = AmazonApiHelper.GetEmptyResponseJson(string.Empty, string.Empty, HttpStatusCode.OK);
            }
            else
            {
                using (AmazonApiHelper apiHelper = new AmazonApiHelper(associateTag, awsAccessKeyId, awsSecretKey))
                {
                    string requestUri = apiHelper.GetRequestUri(keywords);
                    try
                    {
                        responseJson = apiHelper.ExecuteWebRequest(requestUri, keywords);
                    }
                    catch (Exception ex)
                    {
                        responseJson = AmazonApiHelper.GetEmptyResponseJson(keywords, ex.Message, HttpStatusCode.InternalServerError);
                    }
                }
            }

            context.Response.ContentType = "application/json";
            context.Response.Write(responseJson);
        }
コード例 #2
0
        private void BusquedaArticulo()
        {
            string          palabra     = txtProduct.Text;
            AmazonApiHelper AwsApiHelp2 = new AmazonApiHelper(Valor.MyTag(), Valor.MyKeyId(), Valor.SecretKey());
            // string urlSearch2 = AwsApiHelp2.GetRequestUri(palabra);
            string urlSearch2 = Valor.UrlCliente(palabra, comboBox1.SelectedItem.ToString());

            txtUrl.Text = urlSearch2;
            string    json2 = AwsApiHelp2.ExecuteWebRequest(urlSearch2, palabra);
            DataTable dt2   = new DataTable();

            dt2             = Metodo.BuidingDataTable(dt2);
            dt2             = Metodo.DataAddTable(dt2, json2);
            dgv1.DataSource = dt2;
            WebClient    wc;
            MemoryStream ms;
            int          f = 0;

            foreach (DataRow r in dt2.Rows)
            {
                wc = new WebClient();
                byte[] bytes = wc.DownloadData(r["productImgUrl"].ToString());

                ms = new MemoryStream(bytes);
                Image img = Image.FromStream(ms);
                Image img2;
                img2 = Metodo.ResizeImage(img, 6000, 3500);
                if (img2 != null)
                {
                    dgv1.Rows[f].Cells["productImgUrl"].Value = img2;
                }
                else
                {
                    dgv1.Rows[f].Cells["productImgUrl"].Value = img;
                }
                f++;
            }

            Metodo.CaracteristicaGrilla(dgv1);
        }