Exemple #1
0
        private void postDataWithWebClient(DrugBarCode code)
        {
            try
            {
                WebClient wc         = new WebClient();
                string    requestUrl = "http://test.o4bs.com/api/members/drugbarcode";

                JObject carJson  = JObject.FromObject(code);
                string  paramStr = carJson.ToString();

                byte[] postData = Encoding.UTF8.GetBytes(paramStr);

                wc.Headers.Add("Content-Type", "application/json");
                wc.Headers.Add("appkey", "097e8751c3c183edf602f867a5326559");
                wc.Headers.Add("appid", "SyccthZn");

                byte[] responseData = wc.UploadData(requestUrl, "POST", postData); // 得到返回字符流
                String resultValue  = Encoding.UTF8.GetString(responseData);       // 解码

                Console.WriteLine(resultValue);
            }
            catch (Exception e)
            {
                //MessageBox.Show("A6.xaml postDataWithWebClient Error happen"+e);
            }
        }
Exemple #2
0
        private void DoWork()
        {
            if (drugId != null)
            {
                try
                {
                    DrugBarCode code    = new DrugBarCode();
                    string      barcode = drugId;
                    code.sid     = "Vk7Tc-PJx";
                    code.barcode = barcode;

                    postDataWithWebClient(code);
                }
                catch (Exception)
                {
                }
                finally {
                    drugId = string.Empty;
                }
            }
        }