Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HttpWebRequest and querystrings

Status
Not open for further replies.

aepheus

Programmer
Mar 22, 2007
3
US
I'm coding a script that will submit a form for a user on server side. The form handling script was designed to take both post information and querystring information. I have no control over how the form handling script runs. One of the querystring items is a url which must be escaped. Problem is when I escape it and make a Request object it is magically unescaped (checked by printing the Request.Address). I've tried doubly escaping the item and it is not unescaped at all then (still doubly escaped).
I've also tried the new Uri(String Uri, Boolean escaped) constructor which has the same effect.

Any ideas?

Code:
//Make new account web request.
String sPost = "name=value";

byte[] aPostData = Encoding.UTF8.GetBytes(sPost);
HttpWebRequest oReq = (HttpWebRequest)WebRequest.Create(new Uri(" + Server.UrlEncode(" + sPMID + "[pmid]&db=pubmed&dispmax=50&doptcmdl=medline"),true));
oReq.Method = "POST";
oReq.ContentType = "application/x- oReq.ContentLength = aPostData.Length;
Stream oDataStream = oReq.GetRequestStream();
oDataStream.Write(aPostData, 0, aPostData.Length);
oDataStream.Flush();
oDataStream.Close();
 
try escaping using the @ symbol.
Code:
 HttpWebRequest oReq = (HttpWebRequest)WebRequest.Create(new Uri([b]@[/b]"[URL unfurl="true"]https://mydomain/myscript.asp?vendor=PubMed&filter=PubMed&url="[/URL] + Server.UrlEncode([b]@[/b]"[URL unfurl="true"]http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=search&term="[/URL] + sPMID + [b]@[/b]"[pmid]&db=pubmed&dispmax=50&doptcmdl=medline"),true));

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley, @ is used to ignore string escape character \. There's nothing it could help in the described situation.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top