locked
The remote server returned an error: (500) Internal Server Error RRS feed

  • Question

  • User-253463745 posted

    Hi

      String strUrl = "http://catalogues.cataloguecentral.com.au/global/search/search.aspx?";     

            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create(strUrl);
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = "query_xml=<?xml version='1.0' encoding='utf-8' ?><search_xml><search before='25' after='25'><![CDATA[jacket]]> ...Blah Blah";
          //  postData = postData.Replace((char)39, (char)34);
           PostXml(strUrl, postData);


         //   postData = postData.Replace("\\\", string.Empty);
            //string postData = "?query_xml=" + getXMLString();
            //postData = HttpUtility.UrlEncodeToBytes (postData);
            byte[] byteArray = Encoding.UTF8.GetBytes(postData); //Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse(); // Getting Error Here
            // Display the status.
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);
            // Clean up the streams.
            reader.Close();
            dataStream.Close();
            response.Close();

     

      Above code was breaking at  WebResponse response = request.GetResponse(); 

    ( I have tried by pasting http://catalogues.cataloguecentral.com.au/global/search/search.aspx?query_xml=<?xml version='1.0' encoding='utf-8' ?><search_xml><search before='25' after='25'><![CDATA[jacket]]> ...Blah Blah" in Internet explorer and Firefox, It's returning an xml file so no problems with security I have given full rights to this directory)

      Any Idea why it's breaking

     

    Thanks

     

     

     

     

    Thursday, April 16, 2009 8:44 PM

Answers

  • User-1136466523 posted

    Hi,

    From your description, it seems that you met error while requesting that url in your asp.net code, right?

    If so, i think you need to check your application step by step, and try to check the exact url your application is requesting.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 10:10 AM
  • User-253463745 posted

     This is the code that has been solved my problem

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Net;
    using System.IO;
    using System.Text;
    using System.Xml;
    using System.Collections.Generic;

     

     private void GetResponseAsString(string postData, int timeout)
        {

        // Create a request using a URL that can receive a post.
            HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(postData);
            // Set the Method property of the request to POST.
            webRequest.Headers.Clear();
            webRequest.AllowAutoRedirect = true;
            webRequest.Timeout = 1000 * timeout;
            webRequest.PreAuthenticate = true;
            webRequest.ContentType = "application / x - www - form - urlencoded";
            webRequest.Credentials = CredentialCache.DefaultCredentials;
            webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
            webRequest.Timeout = 150000;
            // Create POST data and convert it to a byte array.

            WebResponse webResponse = null;
            StreamReader objSR;
            System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            Stream objStream;
            string sResponse;

            webResponse = (HttpWebResponse)webRequest.GetResponse();
            objStream = webResponse.GetResponseStream();
            objSR = new StreamReader(objStream, encode, true);
            //<<sResponse doesn't contain Unicode char values>>
            sResponse = objSR.ReadToEnd();
           Response.write(sReponse);  // OR Response.write(HttpUtility.HtmlEncode(sResponse))

      

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 28, 2009 11:22 PM

All replies

  • User1712388314 posted

    If you can not debug a server method on search.aspx - just set customErrors element in web.config to Off - server will return an error's full description.

    Friday, April 17, 2009 12:33 AM
  • User-253463745 posted

     Thanks for your Reply

        As I mentioned before my code was breaking at   // Get the response.
            WebResponse response = request.GetResponse(); // Getting Error Here

     we are using third parties search.aspx, The old classic ASP pages are using similar method and working fine. In .net I am getting this error

     The remote server returned an error: (500) Internal Server Error 

    I can't see what is search.aspx because that is out of my scope, I have to pass querystring as xml (search string) and it will returns xml (search result) When I test by copy paste on the browser it works fine i don't why above code was breaking

    Any help 

     

    Sunday, April 19, 2009 7:01 PM
  • User-1136466523 posted

    Hi,

    From your description, it seems that you met error while requesting that url in your asp.net code, right?

    If so, i think you need to check your application step by step, and try to check the exact url your application is requesting.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 10:10 AM
  • User-253463745 posted

     Thanks for your reply

       I have tried the same string (url) in my code, still i am getting the same error. Any help

     

    Thanks

    Tuesday, May 5, 2009 12:23 AM
  • User-253463745 posted

     

     finally i figured out the problem, The error is coming from third party they are still using asp script instead .net

     

    Thanks

    Thursday, May 14, 2009 10:11 PM
  • User-253463745 posted

     This is the code that has been solved my problem

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Net;
    using System.IO;
    using System.Text;
    using System.Xml;
    using System.Collections.Generic;

     

     private void GetResponseAsString(string postData, int timeout)
        {

        // Create a request using a URL that can receive a post.
            HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(postData);
            // Set the Method property of the request to POST.
            webRequest.Headers.Clear();
            webRequest.AllowAutoRedirect = true;
            webRequest.Timeout = 1000 * timeout;
            webRequest.PreAuthenticate = true;
            webRequest.ContentType = "application / x - www - form - urlencoded";
            webRequest.Credentials = CredentialCache.DefaultCredentials;
            webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
            webRequest.Timeout = 150000;
            // Create POST data and convert it to a byte array.

            WebResponse webResponse = null;
            StreamReader objSR;
            System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            Stream objStream;
            string sResponse;

            webResponse = (HttpWebResponse)webRequest.GetResponse();
            objStream = webResponse.GetResponseStream();
            objSR = new StreamReader(objStream, encode, true);
            //<<sResponse doesn't contain Unicode char values>>
            sResponse = objSR.ReadToEnd();
           Response.write(sReponse);  // OR Response.write(HttpUtility.HtmlEncode(sResponse))

      

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 28, 2009 11:22 PM