473,395 Members | 1,496 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,395 software developers and data experts.

get raw headers?

Is there any easy way to get the raw headers (byte[])?

We've got a routine that wants to check the referrer for certain query
string parameters. At the moment, it gets Request.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, start, len) overload
- just an UrlDecode(byte[], start, len, encoding) one.

In general, I was poking around the docs and didn't see any obvious way of
getting the raw bytes of a given header. Is there such a thing?

Thanks
Mark

Jun 27 '08 #1
4 1825
HttpUtility.UrlDecode supports a string, and string supports SubString, so it:

string s = HttpUtility.UrlDecode(header.SubString(iStart,iLen ));

though it woudl be simple to spilt and decode (air code)

var values = new Dictionary<string,string>();
foreach (string s in header.Split('&'))
{
var items = s.Split('=');
if (items.Length 1)
{
values.Add(items[0],HttpUtility.UrlDecode(items[1]));
}
}
-- bruce (sqlwork.com)
"Mark" wrote:
Is there any easy way to get the raw headers (byte[])?

We've got a routine that wants to check the referrer for certain query
string parameters. At the moment, it gets Request.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, start, len) overload
- just an UrlDecode(byte[], start, len, encoding) one.

In general, I was poking around the docs and didn't see any obvious way of
getting the raw bytes of a given header. Is there such a thing?

Thanks
Mark
Jun 27 '08 #2
Hi Mark,

As Bruce has suggested, you can use HttpUtility.UrlDecode(string) overload
to decode the substring from the original UrlReferer path.

As for raw header, it seems ASP.NET hasn't exposed the underlying binary
data. So far you can access the UrlReferer via Request.UrlReferrer property
or manually lookup the Request.Headers collection(as a string value).

Is there any other concerns that you need accessing the raw bytes?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Thread-Topic: get raw headers?
thread-index: Aci5zgEa37thEtzOTsqUd05rnKujlQ==
X-WBNR-Posting-Host: 207.46.193.207
From: =?Utf-8?B?TWFyaw==?= <mm******@nospam.nospam>
Subject: get raw headers?
Date: Mon, 19 May 2008 09:33:01 -0700
>
Is there any easy way to get the raw headers (byte[])?

We've got a routine that wants to check the referrer for certain query
string parameters. At the moment, it gets Request.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, start, len)
overload
>- just an UrlDecode(byte[], start, len, encoding) one.

In general, I was poking around the docs and didn't see any obvious way of
getting the raw bytes of a given header. Is there such a thing?

Thanks
Mark

Jun 27 '08 #3
Hi Bruce, Steven...

Several Microsoft whitepapers on performance optimization for .net say to
steer clear of comparatively wasteful operations like String.Split() for all
the extra objects they create putting burden on the garbage collector. I had
a 1.1 app for reading log files that used Split a lot, and I found with
Perfmon that it was spending 35-45% of the time in garbage collection. I
re-implemented to avoid .Split() and performance improved about 30%.

UrlDecode() had a ranged overload but only for the raw bytes, which seems
kind of odd given how awkward it is to *get* raw bytes of anything you'd want
to UrlDecode().

Thanks
Mark

"Steven Cheng [MSFT]" wrote:
Hi Mark,

As Bruce has suggested, you can use HttpUtility.UrlDecode(string) overload
to decode the substring from the original UrlReferer path.

As for raw header, it seems ASP.NET hasn't exposed the underlying binary
data. So far you can access the UrlReferer via Request.UrlReferrer property
or manually lookup the Request.Headers collection(as a string value).

Is there any other concerns that you need accessing the raw bytes?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Thread-Topic: get raw headers?
thread-index: Aci5zgEa37thEtzOTsqUd05rnKujlQ==
X-WBNR-Posting-Host: 207.46.193.207
From: =?Utf-8?B?TWFyaw==?= <mm******@nospam.nospam>
Subject: get raw headers?
Date: Mon, 19 May 2008 09:33:01 -0700

Is there any easy way to get the raw headers (byte[])?

We've got a routine that wants to check the referrer for certain query
string parameters. At the moment, it gets Request.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, start, len)
overload
- just an UrlDecode(byte[], start, len, encoding) one.

In general, I was poking around the docs and didn't see any obvious way of
getting the raw bytes of a given header. Is there such a thing?

Thanks
Mark

Jun 27 '08 #4
Thanks for the reply Mark,

Yes, the UrlDecode method is not quite useful for those already
encapsulated string values (from raw bytes) in asp.net. However, the
UrlDecode(like many other encoding/decoding methods) belong to the
HttpUtility class which is not restricted to be used in ASP.NET application
only. You can also use it to do UrlEncode/Decode in your own application
which may need to convert some raw byte array to string format encoded
array. For example, if you're writing own http components that may need
such utility function.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?TWFyaw==?= <mm******@nospam.nospam>
References: <6F**********************************@microsoft.co m>
<GE**************@TK2MSFTNGHUB02.phx.gbl>
>Subject: RE: get raw headers?
Date: Tue, 20 May 2008 07:11:01 -0700

Hi Bruce, Steven...

Several Microsoft whitepapers on performance optimization for .net say to
steer clear of comparatively wasteful operations like String.Split() for
all
>the extra objects they create putting burden on the garbage collector. I
had
>a 1.1 app for reading log files that used Split a lot, and I found with
Perfmon that it was spending 35-45% of the time in garbage collection. I
re-implemented to avoid .Split() and performance improved about 30%.

UrlDecode() had a ranged overload but only for the raw bytes, which seems
kind of odd given how awkward it is to *get* raw bytes of anything you'd
want
>to UrlDecode().

Thanks
Mark

"Steven Cheng [MSFT]" wrote:
>Hi Mark,
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
3
by: sam | last post by:
Hello Group, Havent had luck posting it to microsoft.public.dotnet.framework.aspnet.datagridcontrol group. Excuse me for the cross posting. I have a datagrid which needs to be split into multiple...
71
by: Christopher Benson-Manica | last post by:
At what point was the .h dropped from the STL headers? I just had a discussion yesterday with my boss, who said he wanted .h on all the STL includes, despite me protesting that it was not...
1
by: stuart | last post by:
Hi, Can anybody tell me if it is possible to add your own headers through this class. The documenttion seems to be a bit ambiguous, for example the overview of the methods says Specifies the...
3
by: Jacky | last post by:
hi, I am trying to view the custom headers in an ASP.NET page. I am able to view all the standard headers using the method Request.Headers.Get(). But if i set a custom header using...
1
by: Ale News | last post by:
Hi to All.. I must add some custom headers HTTP and then i would to read them.. I used the AppendHeader Method to add my headers but when i try to read the headers i can't see my custom ones.....
2
by: fhtino | last post by:
Hello, I'm trying to create an email message with particular headers. A piece of code: SmtpClient smtp = new SmtpClient("192.168.x.y"); MailMessage msg = new MailMessage("from@xxxxxxx",...
5
by: Milos Prudek | last post by:
I perform a XML-RPC call by calling xmlrpclibBasicAuth which in turn calls xmlrpclib. This call of course sends a HTTP request with correct HTTP headers. The response is correctly parsed by...
4
by: sadieslc | last post by:
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.