 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 26th, 2006, 01:09 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Webresponse contenttype different from request
I have this code and it is causeing a problem because the response contains ü so it has problems.
I want to be able to make the request the same content type as the response and this does not seem to do it. If I debug it the content type of the response is "", so nothing basically and I guess it defaults to something that can not handle foreign characters
----------------------------------------------------------
XmlDocument responseXML = new XmlDocument();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strURL);
req.ContentType = "text/xml;charset=\"ISO-8859-1\"";
req.Method = "POST";
req.ContentLength = strXML.Length;
Stream streamReq = req.GetRequestStream();
StreamWriter w = new StreamWriter(streamReq);
w.Write(strXML);
w.Flush();
w.Close();
streamReq.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream streamResp = resp.GetResponseStream();
responseXML.Load(streamResp);
XmlNodeReader reader = new XmlNodeReader(responseXML);
------------------------------------------------------
|
|

September 26th, 2006, 01:13 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
have you tried something to the effect of:
req.ContentType = "text/xml";
req.Accept = "text/xml";
?
--Stole this from a moderator
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
|
|

September 26th, 2006, 01:25 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah that's what I had initially then i switched it to text/xml;charset=\"ISO-8859-1\. I also tried it using the WebResponse and WebRequest object.
|
|

September 26th, 2006, 01:37 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Your webresponse should be ok; this is how I make all of my WebRequests:
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "text/xml";
StreamWriter streamWriter = new System.IO.StreamWriter(httpWebRequest.GetRequestSt ream());
streamWriter.Write(([xml object]));
streamWriter.Close();
System.Net.HttpWebResponse httpWebResponse = httpWebRequest.GetResponse();
StreamReader streamReader = new System.IO.StreamReader(httpWebResponse.GetResponse Stream());
//More code here
Is there an error being thrown by the run time?
--Stole this from a moderator
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
|
|

September 26th, 2006, 03:05 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah it is a run time error. It crashes on
responseXML.Load(streamResp);
with this message
There is an invalid character in the given encoding. Line 1, position 952.
The character at position 952 is ü
|
|

September 27th, 2006, 03:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Sounds like a UTF-8 encoded page, why are you specifying ISO-8859-1?
--
Joe ( Microsoft MVP - XML)
|
|

September 27th, 2006, 10:42 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah it seems like the response is UTF-8 or some other format that is not able to read foreign characters. I specified ISO-8859-1 because when I took the response and put that in instead of UTF-8 the web browser did not crash, but was okay.
Does this mean there is a problem with the way I'm getting the response and that the app that I'm posting needs to change the encoding on their response, or can I change the response encoding on my side?
*edit*
My fault I didn't quite understand what was going on. Is it possible to change the encoding of the response, not contenttype?
|
|
 |