1

I am programmatically creating a web-request like this

        string url = "http://aksphases:201/min-konto/printpdf.aspx?id=149656222&name=Ink%20And%20Toner";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.CookieContainer = new CookieContainer(); // required for HttpWebResponse.Cookies
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        byte[] data = Encoding.UTF8.GetBytes("email=mymail&password=1234");
        request.ContentLength = data.Length;
        using (Stream stream = request.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }
        HttpWebResponse myWebResponse = (HttpWebResponse)request.GetResponse();
        Stream ReceiveStream = myWebResponse.GetResponseStream();

And in the printpdf.aspx page(you can see it in url) I want to get the query string parameters, when this URL is executed programatically . When I tried usual way

HttpContext.Current.Request.QueryString["id"]

It does not works. Is there anything that I am doing in a wrong way.Or is there any better way to do this?

1
  • You're doing this in two distinct processes, right ? (for example: a standalone console app and an ASP.NET web app hosted in IIS) Have you checked if the request's query parameters are accessible just before you send the request in the "console app? ? And also, have you checked if the HttpContext.Current.Request.Url (in the "web site") is what you actually wanted to send ? Commented Feb 26, 2013 at 10:48

1 Answer 1

1

Where exactly in the Web App are you calling this ?

HttpContext.Current.Request.QueryString["id"]

Here's what I think you should try out: In your client app:

    string url = "http://aksphases:201/min-konto/printpdf.aspx?id=149656222&name=Ink%20And%20Toner";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    // try this
    Debug.WriteLine("About to send request with query=\"{0}\"", request.RequestUri.Query);
    // and check to see what gets printed in the debug output windows

    request.CookieContainer = new CookieContainer(); // required for HttpWebResponse.Cookies
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    byte[] data = Encoding.UTF8.GetBytes("email=mymail&password=1234");
    request.ContentLength = data.Length;

whereas in your ASPX page, try this:

    protected void Page_Load(object sender, EventArgs e) {
        var theUrl = this.Request.Url.ToString();
        Debug.WriteLine(theUrl); // is this the exact URL that you initially requested ?
        // if you have FormsAuthentication or other redirects
        // this might get modified if you're not careful

        var theId = this.Request.QueryString["id"];
        Debug.WriteLine(theId);
    }
Sign up to request clarification or add additional context in comments.

4 Comments

I have tried this.at Debug.WriteLine("About to send request with query=\"{0}\"", request.RequestUri.Query); I am getting correct values.and in server side i am not using aspx page so i can really use the method you had suggested so I tried this HttpContext.Current.Request.Url.ToString(). and it returns a url with out any query string parameters only this much aksphases:201/min-konto/printpdf.aspx
And what are you using on the server ? Is it a Generic Handler ? Are you doing ASP.NET MVC ?
Its an Umbraco(asp.net cms built on MVC) website.and I can only use simple asp.net class files to do things
I don't know what that is but I can tell you this: i sometimes use VisualWebGui to rad-develop web apps. It is on top of ASP.NET as well. One of the things it does is the fact that it "consumes" the query part of the URLs. You still can access the query but in another way. Maybe this Umbraco of yours does the same. Read it's documentation. Also please tell us if you succeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.