我有geoserver,我有很多地图(图层),但我想保护这些图层,我想访问这些图层。我搜索过但结果不起作用,例如其中一个样本是" http://username:password@ipadress/geoserver"但当我尝试访问时,geoserver返回404错误,但当我登录时,服务器返回成功。
访问服务器的第二个样本:那是我的代理
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Proxy(string url)
{
var context = this.HttpContext;
//var dUrl = url.Replace("http://", "");
var dUrl = url;
dUrl = HttpUtility.UrlEncode(dUrl);
//var hede = new Uri(dUrl, UriKind.Relative);
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = context.Request.HttpMethod;
String username = "admin";
String password = "geoserver";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
request.Headers.Add("Authorization", "Basic " + encoded);
if (request.Method == "POST")
{
var content = new System.Text.UTF8Encoding().GetBytes(new System.IO.StreamReader(context.Request.InputStream).ReadToEnd());
request.ContentLength = content.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(content, 0, content.Length);
stream.Close();
}
}
var response = request.GetResponse().GetResponseStream();
if (response == null)
return null; // new JsonResult();
context.Response.Write(new System.IO.StreamReader(response).ReadToEnd());
return null; //Json(new JsonResult(), JsonRequestBehavior.AllowGet);
}
}