473,794 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with unencoded pound signs and WebRequest

1 New Member
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.Collecti ons.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace HattrickHeaven
{
public class HTTPRequest
{

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

// only here for testing
private bool _debug = true;
private string _debugFile = @"d:\inetpub\ww wroot\hattrickh eaven.com\LogFi les\ripperDebug .txt";

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

if(!String.IsNu llOrEmpty(msg))
{
msg += " ";
System.IO.File. AppendAllText(_ debugFile,msg,E ncoding.UTF8);
// System.IO.File. AppendAllText(_ debugFile, msg, Encoding.ASCII) ;
}
}

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

HttpWebRequest client = (HttpWebRequest )WebRequest.Cre ate(URL);
client.Method = "GET";
client.ContentL ength = 0;
client.ContentT ype = "applicatio n/x-www-form-urlencoded;char set=charset=UTF-8";

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

client.Timeout = 40000;
client.UserAgen t = robotAgent;

try
{
// get the response
HttpWebResponse response = (HttpWebRespons e)client.GetRes ponse();

_statusDesc = response.Status Description;
_status = Convert.ToInt32 (response.Statu sCode);

StreamReader ResponseStream = new StreamReader(re sponse.GetRespo nseStream(), Encoding.UTF8);

_responseConten t = ResponseStream. ReadToEnd();

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

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

}

}

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

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

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

Similar topics

3
5163
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://" s = s & Request.ServerVariables("HTTP_HOST") s = s & Request.ServerVariables("URL") If Request.QueryString.Count > 0 Then s = s & "?" & Request.QueryString
4
16813
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 excuse any typos). This page is not a production page - I created it just to try and solve the sign problem I am having. When I put the pound sign () into the input box and submit the form,
6
6895
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"); StreamWriter sw = new StreamWriter("output.txt"); string Line; char delimiter = {'*'}; while((Line = sr.ReadLine()) != null) { string Fields;
2
2634
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 uploading text data from a form. This data is either directly input into a textarea, or is a file stream originating from a .txt file, (or other basic text file (like off Mac or Unix - of course I don't necessarily know at present it's
1
1434
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 round it...? Any assistance gratefully received. Mark
1
1558
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 a DB where the signs are listed, with "longitude" and "latitude". Anytime someone takes a step, I want to show a grid where any square can be reached within 3 steps. And if there's a sign in one grid, I want to show it, so the player can walk...
0
1373
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> <HEAD> <%@ page contentType="application/msexcel" %> <% response.addHeader("Content-Disposition","inline; filename="+ "CONTRACTSAMENDMENTHISTORYEXCEL.xls" + ";" );
8
32803
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. googling, would appreciate some detailed information.
9
14146
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: articleArea.InnerHtml = article.Text . . .. and it works fine (shows chinese characters). But when I put this data into a asp:textbox control, it just shows up as is... (12大&# etc...) Can anyone tell me how to get the characters to appear...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.