Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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;
    }


here is the code i used pl correct me where i went worng
Posted

1 solution

In your second requext, you'll likely have to send proof to the server that your login is valid. I guess that information is somehow stored in the response to your login request (your variable ResponseXML); some part of it must be added to the second request (your variable RequestXML1).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900