Пример #1
0
        public async Task <string> MakePostRequest(string id, string apiName, bool update = false)
        {
            try
            {
                var makeParams = new MakeParams();
                makeParams.AddParam("userRev", Define.UserRev);
                makeParams.AddCommonParams();
                makeParams.AddParam("pid", SaveData.Decrypt(Define.encPid));
                makeParams.AddSignatureParam(id, apiName);
                var httpContent = new StringContent(makeParams.GetParam())
                {
                    Headers =
                    {
                        ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded")
                        {
                            CharSet = "utf-8"
                        }
                    }
                };

                var response = await _postClient.PostAsync(Define.GetApiName(Define.APINAME_TYPE.result)
                                                           , httpContent);

                if (response.IsSuccessStatusCode)
                {
                    var jsonString = await response.Content.ReadAsStringAsync();

                    if (!update)
                    {
                        return(jsonString);
                    }
                    using (var streamWriter = new StreamWriter(Define.GetUpdatePath()))
                    {
                        streamWriter.Write(jsonString);
                        streamWriter.Close();
                    }
                }
                else
                {
                    response.EnsureSuccessStatusCode();
                    MessageBox.Show(@"请求超时");
                }

                return("complete");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
Пример #2
0
        public async Task <int> MakeUpdatePostRequest(string id, string apiName)
        {
            try
            {
                var Params = new MakeParams();
                Params.AddParam("downloadType", "0");
                Params.AddParam("userRev", Define.UserRev);
                Params.AddCommonParams();
                Params.AddParam("pid", SaveData.Decrypt(Define.encPid));
                Params.AddSignatureParam(id, apiName);
                var httpContent = new StringContent(Params.GetParam())
                {
                    Headers =
                    {
                        ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded")
                    }
                };

                var response = await _postClient.PostAsync(apiName
                                                           , httpContent);

                if (response.IsSuccessStatusCode)
                {
                    var jsonString = await response.Content.ReadAsStringAsync();

                    using (var streamWriter = new StreamWriter(Define.GetUpdatePath()))
                    {
                        streamWriter.Write(jsonString);
                        streamWriter.Close();
                    }

                    return(0);
                }

                response.EnsureSuccessStatusCode();
                return(1);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }