Merhaba arkadaşlar, proje bitirme tarihleri gelirken neredeyse hiç bilgi sahibi olmadığımız bir konu olan geonetwork'ün içinde bulduk kendimizi. Yaptığım araştırmaya göre cookie login yaptıran bir sistemi var.Bende ilk olarak sisteme olgin oluyorum burda sıkıntı yok. gelen jsession id'sini headere yükleyip insert moduna geçiyorum fakat burda habire unauthorize hatası alıyorum bilgisi olan varsa yardım edebilirmi. Küçük bir kod bloğu alt tarafta
public string SendXmlToGeoNetwork(string xml, string ServerUrl)
{
if (Login())
{
string answer = postRequest(xml, ServerUrl);
return answer;
}
return "";
}
public bool Login() {
string LoginText = "<request><username>admin</username><password>admin</password></request>";
string LoginUrl = ConfigurationManager.AppSettings["geoNetworklocal"].ToString() + "srv/en/xml.user.login";
try
{
string answer = postRequest(LoginText, LoginUrl);
if (answer.Contains("<ok"))
return true;
return false;
}
catch {
return false;
}
}
HttpWebRequest webRequest;
HttpWebResponse webResponse;
private string header;
private string postRequest(String RequestXML, string ServerURL)
{
int timeout = 90000;
int connectionLimit = 10;
string responseXML = string.Empty;
try
{
webRequest = (HttpWebRequest)WebRequest.Create(ServerURL);
if (!string.IsNullOrEmpty(header))
{
webRequest.Headers.Add("Set-Cookie", header);
}
webRequest.Credentials = new NetworkCredential("admin", "admin");
webRequest.Timeout = timeout;
webRequest.KeepAlive = true;
webRequest.ServicePoint.ConnectionLimit = connectionLimit;
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.Method = "POST";
webRequest.ContentType = "application/xml";
byte[] byteArray = Encoding.UTF8.GetBytes(RequestXML);
Stream strm = webRequest.GetRequestStream();
strm.Write(byteArray, 0, byteArray.Length);
strm.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse();
header= webResponse.Headers["Set-Cookie"].ToString();
Encoding enc = Encoding.GetEncoding("utf-8");
StreamReader reader = new StreamReader(webResponse.GetResponseStream(), enc);
responseXML = reader.ReadToEnd();
reader.Close();
webResponse.Close();
}
catch (Exception ex)
{
throw (ex);
}
return responseXML;
}
şimdiden teşekkür ederim.