Esempio n. 1
0
        public async Task <string> Post(string uriname, string title, string content, string deviceId = "UnkownDevice")
        {
            try
            {
                for (int i = 0; i < RepeatQueryCount; i++)
                {
                    var    handler = new HtmlCharSetHandler();
                    String url     = IpAddress;
                    httpClient.DefaultRequestHeaders.Accept.Clear();
                    httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    //httpClient.BaseAddress = new Uri(url);
                    url = IpAddress + uriname;
                    List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
                    paramList.Add(new KeyValuePair <string, string>("GpContent", content));
                    paramList.Add(new KeyValuePair <string, string>("GpType", "类型"));
                    paramList.Add(new KeyValuePair <string, string>("SendTime", DateTime.Now.ToString("yyyyMMddHHmmss")));
                    paramList.Add(new KeyValuePair <string, string>("GpTitle", title));
                    var response = await httpClient.PostAsync(new Uri(url), new FormUrlEncodedContent(paramList));

                    if (response.IsSuccessStatusCode)
                    {
                        string responseString = await response.Content.ReadAsStringAsync();

                        // 判断是否成功
                        if (responseString.IndexOf("GpSuccess") != -1)
                        {
                            return(responseString);
                        }
                        else
                        {
                            // 失败了
                            return(responseString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("未知原因失败");
        }