This Question is Assumed Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
2 Replies Last post: Apr 2, 2008 12:06 PM by wbardwell

Passing parameters to web request

Mar 27, 2008 6:54 AM

Click to view mmitra's profile Level 1 mmitra 1 posts since
Mar 7, 2008
Hi All

While making a webrequest, I am passing a parameter through URL., as a query string (not as header ).
The url works well in the browser. But when trying to access the same thoru curl program, the parameter becomes null.
(Rest Webservice receives it as null ).

Pls suggest what can go wrong??

sample code :

let service-url:Url = {url web-url & "Products" & tick & ".aspx?OrderNo=" & OrderNo & ""}
{with-open-streams
in = {read-open {service-url.set-query "?format=xml&rows=5000"}}
do
let rs:TestRecordSet = {TestRecordSet Product-rf}
let p:SAXParser = {SAXParser}
{p.set-content-handler {RecordSetHandler rs, "Products" }}
let source:InputSource = {InputSource character-stream = in}
{with rs.batch-events? = true do
{p.parse source}}
{return rs}

Regards,
Sreenu

Click to view cbarber's profile Curl cbarber 115 posts since
Sep 27, 2007
1. Re: Passing parameters to web request Mar 27, 2008 12:11 PM
I don't know if this explains your problem but that code initializes the 'service-url' variable with a Url containing a query but opens the stream using a different version of the Url that replaces the original query with "?format=xml&rows=5000". In other words, the set-query method on Url replaces the entire query with a new one; it does not append to the existing query. The Url class does not provide any API for merging queries, so you would have to write something like this to add to a possibly non-empty query:

{define-proc {append-to-url-query u:Url, s:String}:Url
    def old-query = u.query
    def query =
        {if old-query == "" then
            {format "?%s", s}
         else
            {format "%s&%s", old-query, s}
        }
    {return {u.set-query query}}
}
Click to view wbardwell's profile Curl wbardwell 46 posts since
Oct 31, 2007
2. Re: Passing parameters to web request Apr 2, 2008 12:06 PM
in response to: cbarber

You might be able to use HttpFormData to manage the parameters, and set the query on the Url to the return from HttpFormData.request-data-urlencoded-string.

But your initial problem was due to Url.set-query resetting the whole query.