Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old September 26th, 2006, 01:09 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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);
------------------------------------------------------

 
Old September 26th, 2006, 01:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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.
 
Old September 26th, 2006, 01:25 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old September 26th, 2006, 01:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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.
 
Old September 26th, 2006, 03:05 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ü

 
Old September 27th, 2006, 03:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sounds like a UTF-8 encoded page, why are you specifying ISO-8859-1?

--

Joe (Microsoft MVP - XML)
 
Old September 27th, 2006, 10:42 AM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?





Similar Threads
Thread Thread Starter Forum Replies Last Post
WebRequest/WebResponse form submit problem. HELP! MAtkins ASP.NET 1.0 and 1.1 Professional 2 December 23rd, 2010 12:28 AM
Returning a custom WebResponse to the browser DudeBori82 ASP.NET 2.0 Professional 5 September 28th, 2006 07:53 AM
Getting correct encoding from a webresponse Jonax VB.NET 0 December 21st, 2004 05:37 AM
Problem with Response.ContentType nagesh_vasa XML 1 May 23rd, 2004 01:41 PM
Response.ContentType jcsierra ASP.NET 1.x and 2.0 Application Design 0 September 8th, 2003 11:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.