locked
httpwebresponse & querystring parameters RRS feed

  • Question

  • Why does HttpWebRequest sometimes ignore nested parameters : 

    The following 2 restful service calls work when called in a browser 

    http://localhost/App/OtherService?Action=read&rowcount=2

    http://localhost/App/OtherService?Action=Update&id=11&Title=aa

    The first one retrieves two rows of data. & the second updates the title of record no 11

    They behave differently when called with the following function 

    public string HttpGet(string url)

            {
                HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
                string result = null;
                using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(resp.GetResponseStream());
                    result = reader.ReadToEnd();
                }
                return result;
            }

    This works

    http://localhost/App/HttpGet?url=http://localhost/App/OtherService?Action=read&rowcount=2

    ( Actually in hindsite this partially fails too because rowcount is not passed through to the httpwebresponse object   & the querstring is reinterpretted as "?ActionRequest=readmany"....  It appears to work because I only have 2 records in the database to query.

    This fails because the Title & Id parameters are empty by the time we reach OtherService

    http://localhost/App/HttpGet?url=http://localhost/App/OtherService?Action=Update&id=11&Title=aa


    Richard


    • Edited by Richard Scannell Tuesday, September 11, 2012 12:05 PM
    • Moved by John Saunders Tuesday, September 11, 2012 11:48 PM networking issue (From:ASMX Web Services and XML Serialization)
    Tuesday, September 11, 2012 11:57 AM

Answers

  • Actually this is not anything to do with httpwebresponse or request....

    When I force the URL in the code:

    url2 = "http://localhost:App/OtherService?Action=Update&Title=abc&id=11";
    Uri targeturi = new Uri(url2);
    HttpWebRequest req = WebRequest.Create(targeturi) as HttpWebRequest;

    Then it works.  

    The fault seems to be that the incoming parameters forget all values after the  first "&" : 

    Invoking http://localhost:App/HttpGet?url=http://localhost/App/OtherService?Action=Update&id=11&Title=abcde

    leads to a value for "url" of http://localhost/App/OtherService?Action=Update.  

    So to address this I replaced the & in the url parm with a %26 

    http://localhost:App/HttpGet?url=http://localhost/App/OtherService?Action=Update%26id=11%26Title=abcde

    & by the time it reached OtherService, they had reverted to & 



    Richard


    Tuesday, September 11, 2012 1:19 PM

All replies

  • Actually this is not anything to do with httpwebresponse or request....

    When I force the URL in the code:

    url2 = "http://localhost:App/OtherService?Action=Update&Title=abc&id=11";
    Uri targeturi = new Uri(url2);
    HttpWebRequest req = WebRequest.Create(targeturi) as HttpWebRequest;

    Then it works.  

    The fault seems to be that the incoming parameters forget all values after the  first "&" : 

    Invoking http://localhost:App/HttpGet?url=http://localhost/App/OtherService?Action=Update&id=11&Title=abcde

    leads to a value for "url" of http://localhost/App/OtherService?Action=Update.  

    So to address this I replaced the & in the url parm with a %26 

    http://localhost:App/HttpGet?url=http://localhost/App/OtherService?Action=Update%26id=11%26Title=abcde

    & by the time it reached OtherService, they had reverted to & 



    Richard


    Tuesday, September 11, 2012 1:19 PM
  • Tanks for letting us know. :-)

    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, please vote and/or mark the question answered. Available for contract programming.

    Friday, September 14, 2012 11:05 AM