Subject: Webresponse contenttype different from request
Posted By: mikehsu317 Post Date: 9/26/2006 1:09:49 PM
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);   
------------------------------------------------------

Reply By: dparsons Reply Date: 9/26/2006 1:13:37 PM
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.
Reply By: mikehsu317 Reply Date: 9/26/2006 1:25:27 PM
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.

Reply By: dparsons Reply Date: 9/26/2006 1:37:03 PM
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.GetRequestStream());
streamWriter.Write(([xml object]));
streamWriter.Close();

System.Net.HttpWebResponse httpWebResponse = httpWebRequest.GetResponse();
StreamReader streamReader = new System.IO.StreamReader(httpWebResponse.GetResponseStream());

//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.
Reply By: mikehsu317 Reply Date: 9/26/2006 3:05:05 PM
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 ü

Reply By: joefawcett Reply Date: 9/27/2006 3:05:06 AM
Sounds like a UTF-8 encoded page, why are you specifying ISO-8859-1?

--

Joe (Microsoft MVP - XML)
Reply By: mikehsu317 Reply Date: 9/27/2006 10:42:51 AM
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?

Go to topic 50309

Return to index page 163
Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156
Return to index page 155
Return to index page 154