本文介绍了远程服务器返回403禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我使用以下代码获取响应,得到登录服务响应,但无法从url(http://localhost:8080/geonetwork/srv/en/xml.metadata.get)获取响应,最终我得到了错误403禁止
Hi
i used the following code to get the response i got the response for login service but cannot get the response from the url (http://localhost:8080/geonetwork/srv/en/xml.metadata.get) and i ended up getting the error 403 forbidden
protected void Page_Load(object sender, EventArgs e)
{
string RequestXML = "<request>" +
"<username>admin</username>" +
"<password>admin</password></request>";
string ServerURL = "http://localhost:8080/geonetwork/srv/en/xml.user.login";
string ResponseXML = postRequest(RequestXML, ServerURL);
//= ResponseXML.ToString();
string ServerURL1 = "http://localhost:8080/geonetwork/srv/en/xml.metadata.get";
string RequestXML1 = "<request>" +
"<uuid>5915639e-777c-4339-93ad-c4037f2eeb77</uuid>" +
"</request>";
string ResponseXML1 = postRequest(RequestXML1, ServerURL1);
Label1.Text = ResponseXML1.ToString();
}
private string postRequest(String RequestXML, string ServerURL)
{
int timeout = 90000;
int connectionLimit = 10;
string responseXML = string.Empty;
try
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerURL);
webRequest.Timeout = timeout;
webRequest.KeepAlive = true;
webRequest.ServicePoint.ConnectionLimit = connectionLimit;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml";
byte[] byteArray = Encoding.UTF8.GetBytes(RequestXML);
Stream strm = webRequest.GetRequestStream();
strm.Write(byteArray, 0, byteArray.Length);
strm.Close();
HttpWebResponse webResponse =(HttpWebResponse)webRequest.GetResponse();
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;
}
这是我用来纠正我去过的地方的代码g
here is the code i used pl correct me where i went worng
推荐答案
这篇关于远程服务器返回403禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!