473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem with unencoded pound signs and WebRequest

I am having trouble with a C# proxy page I am writing which allows me to do cross domain AJAX calls with Javascript.
The problem is with certain pages that contain pound signs £ that are not HTML encoded in the source that I am trying
to extract with the WebRequest and WebResponse objects.
The page is using a charset of iso-8859-1 which I think is the problem as my object is using UTF-8. I have created
two test pages one using UTF-8 the other iso-8859-1

http://www.strictly-software.com/test_pound_iso.htm
http://www.strictly-software.com/test_pound_utf8.htm

I can extract the unencoded pound signs successfully from the UTF-8 page but not the ISO page. Obviously I have no control
over the source content that I want to extract so is there a way of getting the pound signs back instead of ? or squares?

I have tried numerous methods e.g byte arrays, memory streams, changing the encoding object to ASCII, supplying content-types
and charsets etc but nothing seems to work.

The code is below

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace HattrickHeaven
{
public class HTTPRequest
{

private int _status = 0;
private string _statusDesc = "";
private string _responseContent = "";
private string _errorType = "";
private bool _retry = false;

// only here for testing
private bool _debug = true;
private string _debugFile = @"d:\inetpub\wwwroot\hattrickheaven.com\LogFiles\r ipperDebug.txt";

private void ShowDebug(string msg)
{
if(!_debug) return;

if(!String.IsNullOrEmpty(msg))
{
msg += " ";
System.IO.File.AppendAllText(_debugFile,msg,Encodi ng.UTF8);
// System.IO.File.AppendAllText(_debugFile, msg, Encoding.ASCII);
}
}

public HTTPRequest(string URL, WebProxy proxy, string robotAgent)
{

HttpWebRequest client = (HttpWebRequest)WebRequest.Create(URL);
client.Method = "GET";
client.ContentLength = 0;
client.ContentType = "application/x-www-form-urlencoded;charset=charset=UTF-8";

if (proxy != null)
{
client.Proxy = proxy;
}

client.Timeout = 40000;
client.UserAgent = robotAgent;

try
{
// get the response
HttpWebResponse response = (HttpWebResponse)client.GetResponse();

_statusDesc = response.StatusDescription;
_status = Convert.ToInt32(response.StatusCode);

StreamReader ResponseStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);

_responseContent = ResponseStream.ReadToEnd();

ResponseStream.Close();
response.Close();

}
catch (Exception err)
{
_errorType = err.Message.ToString();

}

}

public int StatusCode
{
get { return _status; }
}
public string StatusDesc
{
get { return _statusDesc; }
}
public string Response
{
get { return _responseContent; }
}
public string ErrorType
{
get { return _errorType; }
}
public bool Retry
{
get { return _retry; }
}
}
}

Thanks for any help
Nov 18 '09 #1
0 2485

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: George Hester | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;301464 Look down at the MyPage.asp example. You will see that Microsoft does this: 'Costruct the URL for the current page s = "http://"...
4
by: ben | last post by:
Hi all, I have a simple PHP page that takes values from a form and puts them in a database (MySQL). The code is in a file test.php, which I have typed in at the bottom of this post (please...
6
by: Anthony | last post by:
When using StreamReader/Writer to process an input text file to an output text file the pound signs (£) simply disappear. Sample code: StreamReader sr = new StreamReader("input.txt");...
2
by: Jim Lawton | last post by:
Hi, ..net c# httphandler straight html form at browser. GBP pound sign problem (I know I know - I *can* decode it, but I've got to understand what and why I should be doing stuff) I am...
1
by: Mark Rae | last post by:
Hi, Suddenly (at least, I think so) when I rebuild a web deployment project in VS.NET 2005, it strips off British pound signs e.g. £10 becomes 10. Has anyone else seen this...? Is there a way...
1
by: gilbert.havlik | last post by:
Greetings! Please be so kind and take a few minutes, I believe any mind other than mine can solve this. I am writing a game. As you wander through the gameworld, you may come upon signs. I have...
0
by: radhi | last post by:
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:html>...
8
by: davoti | last post by:
Hi, I never truly understand how a macro with ## work in C, for example, if I define #define X X##_YZ what and how does this translated into after compilation? Can't find similar info....
9
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
OK I have some Chinese text in sql server column that looks like this: 12大专题调研破解广东科学å‘展难题 This is unicode? Anyway, I put this data into a text area like this:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.