& delimeter in query string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I want to make an http post request to a site. I want to pass a
paramaeter having xml such as report=<abc>abc</abc> to it. When I try to do
this, is gives exception. And If send report=<abc>abc</abc>, it takes report
as empty string as it assumes & as delimeter. So how can I pass as xml in
http post request.

Thanks,
Sushi
 
You can't send <,> symbol through querystring.
So you have to replace and send with some other character and againg you
have change that.

For Example: report=@abc!abc@/abc!

then you have to replace the querystring value as
"@abc!abc@/abc!".Replace("@","<").Replace("!",">")

Regards,
Amal
 
sushi said:
Hello,
I want to make an http post request to a site. I want to pass a
paramaeter having xml such as report=<abc>abc</abc> to it. When I try
to do this, is gives exception. And If send report=<abc>abc</abc>, it
takes report as empty string as it assumes & as delimeter. So how can
I pass as xml in http post request.

If you do a HTTP POST, you can put your payload in the request body.

Cheers,
 
But how to send data through the HttpWebRequest class object. I am using
HttpWebRequest class so as to send an HTTP Post request.

Thanks
 
sushi said:
But how to send data through the HttpWebRequest class object. I am
using HttpWebRequest class so as to send an HTTP Post request.

Write your data to the request stream.

Here's a sample method that allows you post any kind of binary contents:

public void PostBinary(string url, byte[] bytes, string contentType)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = contentType;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}

using (HttpWebResponse response =
(HttpWebResponse) request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK)
{
string message = String.Format(
"POST failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
}
}

Assuming you have an XML string "xml", a target URL "url", and you want
to use UTF-8 encoding, all you need to do is

byte[] bytes = Encoding.UTF8.GetBytes(xml);
PostBinary(url, bytes, "text/xml");

Cheers,
 
Back
Top