S
scottf35
Hi,
I am working on (read that - upgrading) an application. This
application creates an HTTPWebRequest object, populates it with values
which are then sucked out of the Request.Form object (eg someVariable =
Request.Form)
My problem is that the app doesn't allow input of non-ASCII data in the
form. To resolve this I have replace the ContentType from
"application/x-www-form-urlencoded" to "multipart/form-data".
Now I can accept non-ASCII characters however the Request.Form is
empty. When I swap back to "application/x-www-form-urlencoded" for the
ContentType all is well but I have customers from around the world and
some of them use non-ASCII charaters and the way the code is written I
need data in the Request.Form.
Am I missing something? Can I populate the Form using the
"multipart/form-data" ContentType?
Is there another way to pass data into the form besides the way I am
doing it (below).
<code>
// create the request object
HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create(url + "?"
+ base.Request.QueryString);
// create the values to insert into the request object
objArray1 = new object[3] { "Value1=", value1, "&Value2=", value2,
"&Value3=",value3} ;
string text1 = string.Concat(objArray1);
text1 = text1.Replace(" ", "%20");
request1.ContentLength = text1.Length;
// here is the trouble
request1.ContentType = "multipart/form-data"; //
"application/x-www-form-urlencoded" works fine
request1.Method = "POST";
// At this point I insert the new "Values" in to the form (works unless
I use "multipart/form-data")
StreamWriter writer1 = new StreamWriter(request1.GetRequestStream());
writer1.Write(text1); // text1 was populated earlier with the new
values to insert into the form
</code>
At this point I can get a response object so I can look at the request:
<code>
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse();
stream1 = response1.GetResponseStream();
reader1 = new StreamReader(stream1, Encoding.ASCII);
string text3 = reader1.ReadToEnd();
</code>
I can now look into text3 to tell whether the data from text1 (the
values to insert) has made it into the Request.Form object.
Thats how I do it.
Any ideas or suggestions would be great!
I am working on (read that - upgrading) an application. This
application creates an HTTPWebRequest object, populates it with values
which are then sucked out of the Request.Form object (eg someVariable =
Request.Form)
My problem is that the app doesn't allow input of non-ASCII data in the
form. To resolve this I have replace the ContentType from
"application/x-www-form-urlencoded" to "multipart/form-data".
Now I can accept non-ASCII characters however the Request.Form is
empty. When I swap back to "application/x-www-form-urlencoded" for the
ContentType all is well but I have customers from around the world and
some of them use non-ASCII charaters and the way the code is written I
need data in the Request.Form.
Am I missing something? Can I populate the Form using the
"multipart/form-data" ContentType?
Is there another way to pass data into the form besides the way I am
doing it (below).
<code>
// create the request object
HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create(url + "?"
+ base.Request.QueryString);
// create the values to insert into the request object
objArray1 = new object[3] { "Value1=", value1, "&Value2=", value2,
"&Value3=",value3} ;
string text1 = string.Concat(objArray1);
text1 = text1.Replace(" ", "%20");
request1.ContentLength = text1.Length;
// here is the trouble
request1.ContentType = "multipart/form-data"; //
"application/x-www-form-urlencoded" works fine
request1.Method = "POST";
// At this point I insert the new "Values" in to the form (works unless
I use "multipart/form-data")
StreamWriter writer1 = new StreamWriter(request1.GetRequestStream());
writer1.Write(text1); // text1 was populated earlier with the new
values to insert into the form
</code>
At this point I can get a response object so I can look at the request:
<code>
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse();
stream1 = response1.GetResponseStream();
reader1 = new StreamReader(stream1, Encoding.ASCII);
string text3 = reader1.ReadToEnd();
</code>
I can now look into text3 to tell whether the data from text1 (the
values to insert) has made it into the Request.Form object.
Thats how I do it.
Any ideas or suggestions would be great!