91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#調用百度API方法,POST和GET請求

發布時間:2020-07-30 13:08:18 來源:網絡 閱讀:2583 作者:逆光翱翔 欄目:編程語言
        #region Get請求
        /// <summary>  	
        /// HTTP GET方式請求數據.  	
        /// </summary>  	
        /// <param name="url">URL.</param>  	
        /// <returns>返回數據</returns>  	
        private static string HttpGet(string url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "GET";
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;

            WebResponse response = null;
            string responseStr = null;

            try
            {
                response = request.GetResponse();

                if (response != null)
                {
                    StreamReader reader =
    new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    responseStr = reader.ReadToEnd();
                    reader.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                request = null;
                response = null;
            }

            return responseStr;
        }
        #endregion


        #region POST請求
        /// <summary>  	
        /// HTTP POST方式請求數據  	
        /// </summary>  	
        /// <param name="url">URL.</param>  	
        /// <returns></returns>  	
        private static string HttpPost(string url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;

            WebResponse response = null;
            string responseStr = null;

            try
            {
                response = request.GetResponse();
                if (response != null)
                {
                    StreamReader reader = new
    StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    responseStr = reader.ReadToEnd();
                    //File.WriteAllText(Server.MapPath("~/") + @"\test.txt", responseStr);	
                    reader.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                request = null;
                response = null;
            }

            return responseStr;
        }

        #endregion


        #region HTTP POST方式請求數據
        /// <summary>    
        /// HTTP POST方式請求數據    
        /// </summary>    
        /// <param name="url">URL.</param>    
        /// <param name="param">POST的數據</param>    
        /// <returns></returns>    
        public static string HttpPost(string url, string param)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;

            StreamWriter requestStream = null;
            WebResponse response = null;
            string responseStr = null;

            try
            {
                requestStream = new StreamWriter(request.GetRequestStream());
                requestStream.Write(param);
                requestStream.Close();

                response = request.GetResponse();
                if (response != null)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    responseStr = reader.ReadToEnd();
                    File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~//weixin/Weixin/") + @"\test.txt", responseStr);
                    reader.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                request = null;
                requestStream = null;
                response = null;
            }

            return responseStr;
        }

        #endregion

使用事例,調用百度API

	//非百度經緯度轉化為百度經緯度
        public static string Baidull = "http://api.map.baidu.com/geoconv/v1/?coords={0}&from=1&to=5&ak={1}";

	BaidumapAK;//百度開發者AK;

       #region 非百度經緯度轉化為百度經緯度
        /// <summary>
        /// 非百度經緯度轉化為百度經緯度
        /// </summary>
        /// <param name="latitude">緯度</param>
        /// <param name="longitude">經度</param>
        /// <returns>百度緯度,經度</returns>
        public static string GetBaidull(string latitude, string longitude)
        {

            string text = "";
            string location = longitude + "," + latitude;
            string url = string.Format(Baidull, location, BaidumapAK);
            string response = HttpGet(url);

            JObject jo = new JObject();
            jo = (JObject)JsonConvert.DeserializeObject(response);
            
            latitude = jo["result"][0]["y"].ToString();
            longitude = jo["result"][0]["x"].ToString();
            text = latitude + "," + longitude;
            
            return text;
        }


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

依安县| 城市| 连州市| 柏乡县| 军事| 开鲁县| 赤峰市| 城市| 嘉义市| 吉林市| 迭部县| 陆川县| 正蓝旗| 衡阳市| 满洲里市| 金堂县| 长宁县| 海宁市| 丰都县| 三门县| 十堰市| 西宁市| 门源| 大渡口区| 正镶白旗| 昌乐县| 明星| 达拉特旗| 华安县| 林州市| 莱芜市| 衡南县| 宁城县| 新平| 华亭县| 吴堡县| 雅江县| 利津县| 永康市| 祁连县| 湘阴县|