Web Developer Friends

List of HTTP headers

Posted by: viralsarvaiya on: November 13, 2009

HTTP Headers form the core of an HTTP request, and are very important in an HTTP response. They define various characteristics of the data that is requested or the data that has been provided. The headers are separated from the request or response body by a blank line. HTTP headers can be near-arbitrary strings, but only some are commonly understood.

Requests

Header Description Example
Accept Content-Types that are acceptable Accept: text/plain
Accept-Charset Character sets that are acceptable Accept-Charset: iso-8859-5
Accept-Encoding Acceptable encodings Accept-Encoding: compress, gzip
Accept-Language Acceptable languages for response Accept-Language: da
Accept-Ranges Allows the server to indicate its acceptance of range requests for a resource Accept-Ranges: bytes
Authorization Authentication credentials for HTTP authentication Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Cache-Control Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain Cache-Control: no-cache
Connection What type of connection the user-agent would prefer Connection: close
Cookie an HTTP cookie previously sent by the server with Set-Cookie (below) Cookie: $Version=1; UserId=JohnDoe
Content-Length The length of the request body in octets (8-bit bytes) Content-Length: 348
Content-Type The mime type of the body of the request (used with POST and PUT requests) Content-Type: application/x-www-form-urlencoded
Date The date and time that the message was sent Date: Tue, 15 Nov 1994 08:12:31 GMT
Expect Indicates that particular server behaviors are required by the client Expect: 100-continue
From The email address of the user making the request From: user@email.com
Host The domain name of the server (for virtual hosting), mandatory since HTTP/1.1 Host: en.wikipedia.org
If-Match Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it. If-Match: "737060cd8c284d8af7ad3082f209582d"
If-Modified-Since Allows a 304 Not Modified to be returned if content is unchanged If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
If-None-Match Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag If-None-Match: "737060cd8c284d8af7ad3082f209582d"
If-Range If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity If-Range: "737060cd8c284d8af7ad3082f209582d"
If-Unmodified-Since Only send the response if the entity has not been modified since a specific time. If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
Max-Forwards Limit the number of times the message can be forwarded through proxies or gateways. Max-Forwards: 10
Pragma Implementation-specific headers that may have various effects anywhere along the request-response chain. Pragma: no-cache
Proxy-Authorization Authorization credentials for connecting to a proxy. Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Range Request only part of an entity. Range: bytes=500-999
Referer This is the address of the previous web page from which a link to the currently requested page was followed. Referer: http://en.wikipedia.org/wiki/Main_Page
TE The transfer encodings the user agent is willing to accept: the same values as for the response header Transfer-Encoding can be used, plus the “trailers” value (related to the “chunked” transfer method) to notify the server it accepts to receive additional headers (the trailers) after the last, zero-sized, chunk. TE: trailers, deflate;q=0.5
Upgrade Ask the server to upgrade to another protocol. Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
User-Agent The user agent string of the user agent User-Agent: Mozilla/5.0 (Linux; X11)
Via Informs the server of proxies through which the request was sent. Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
Warn A general warning about possible problems with the entity body. Warn: 199 Miscellaneous warning

Responses

Header Description Example
Accept-Ranges What partial content range types this server supports Accept-Ranges: bytes
Age The age the object has been in a proxy cache in seconds Age: 12
Allow Valid actions for a specified resource. To be used for a 405 Method not allowed Allow: GET, HEAD
Cache-Control Tells all caching mechanisms from server to client whether they may cache this object Cache-Control: no-cache
Content-Encoding The type of encoding used on the data Content-Encoding: gzip
Content-Language The language the content is in Content-Language: da
Content-Length The length of the response body in octets (8-bit bytes) Content-Length: 348
Content-Location An alternate location for the returned data Content-Location: /index.htm
Content-Disposition An opportunity to raise a “File Download” dialogue box for a known MIME type Content-Disposition: attachment; filename=fname.ext
Content-MD5 A Base64-encoded binary MD5 sum of the content of the response Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==
Content-Range Where in a full body message this partial message belongs Content-Range: bytes 21010-47021/47022
Content-Type The mime type of this content Content-Type: text/html; charset=utf-8
Date The date and time that the message was sent Date: Tue, 15 Nov 1994 08:12:31 GMT
ETag An identifier for a specific version of a resource, often a Message Digest, see ETag ETag: "737060cd8c284d8af7ad3082f209582d"
Expires Gives the date/time after which the response is considered stale Expires: Thu, 01 Dec 1994 16:00:00 GMT
Last-Modified The last modified date for the requested object, in RFC 2822 format Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT
Location Used in redirection, or when a new resource has been created. Location: http://www.w3.org/pub/WWW/People.html
Pragma Implementation-specific headers that may have various effects anywhere along the request-response chain. Pragma: no-cache
Proxy-Authenticate Request authentication to access the proxy. Proxy-Authenticate: Basic
Refresh Used in redirection, or when a new resource has been created. This refresh redirects after 5 seconds.
(This is a proprietary/non-standard header extension introduced by Netscape and supported by most web browsers.)
Refresh: 5; url=http://www.w3.org/pub/WWW/People.html
Retry-After If an entity is temporarily unavailable, this instructs the client to try again after a specified period of time. Retry-After: 120
Server A name for the server Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
Set-Cookie an HTTP cookie Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1
Trailer The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding. Trailer: Max-Forwards
Transfer-Encoding The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity. Transfer-Encoding: chunked
Vary Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server. Vary: *
Via Informs the client of proxies through which the response was sent. Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
Warning A general warning about possible problems with the entity body. Warning: 199 Miscellaneous warning
WWW-Authenticate Indicates the authentication scheme that should be used to access the requested entity. WWW-Authenticate: Basic

Get HTML code from URL in ASP.NET

Posted by: viralsarvaiya on: November 10, 2009

To get HTML of web page you need only few lines of code.

To start, place two TextBox controls named txtURL and txtPageHTML, and one button control on web form, like in image bellow:

Web form for getting page HTML at design time

Now, on button’s click event function, place this code:

[ C# ]

// We need these namespaces
using System;
using System.Text;
using System.Net;

public partial class DefaultCS : System.Web.UI.Page
{

protected void btnGetHTML_Click(object sender, EventArgs e)
{
// We’ll use WebClient class for reading HTML of web page
WebClient MyWebClient = new WebClient();

// Read web page HTML to byte array
Byte[] PageHTMLBytes;
if (txtURL.Text != “”)
{
PageHTMLBytes = MyWebClient.DownloadData(txtURL.Text);

// Convert result from byte array to string
// and display it in TextBox txtPageHTML
UTF8Encoding oUTF8 = new UTF8Encoding();
txtPageHTML.Text = oUTF8.GetString(PageHTMLBytes);
}
}
}

[ VB.NET ]

‘ We need these namespaces
Imports System
Imports System.Text
Imports System.Net

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnGetHTML_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetHTML.Click
‘ We’ll use WebClient class for reading HTML of web page
Dim MyWebClient As WebClient = New WebClient()

‘ Read web page HTML to byte array
Dim PageHTMLBytes() As Byte
If txtURL.Text <> “” Then
PageHTMLBytes = MyWebClient.DownloadData(txtURL.Text)

‘ Convert result from byte array to string
‘ and display it in TextBox txtPageHTML
Dim oUTF8 As UTF8Encoding = New UTF8Encoding()
txtPageHTML.Text = oUTF8.GetString(PageHTMLBytes)
End If
End Sub

End Class

 

Now you can start sample project, type some valid URL in first TextBox control and click to “btnGetHTML” button. Code listed above will return HTML code of requested URL and display it in second text box, like in image bellow:

HTML code is read and shown in text box

As you see, loading of HTML code of web page is relatively easy. Analyzing of this data is much harder and depends of page structure.

Reference :

http://www.beansoftware.com/ASP.NET-FAQ/Read-Page-HTML.aspx

Get Primary key – Foreign key relations table in sql server

Posted by: viralsarvaiya on: November 4, 2009

select * from information_schema.constraint_column_usage

This Query give the list of the table with the constraint

select * from information_schema.referential_constraints

this query give the list of the table with the foreign key constraint

now the query to find the relations

select

tblAll.table_name as Primary_TableName,

tblAll.column_name as Primary_TableColumn,

tblFK.table_name as ForeignKey_TableName,

tblFK.column_name as ForeignKey_ColumnName

from information_schema.constraint_column_usage tblAll

inner join information_schema.referential_constraints tblAllFK on

tblAllFK.unique_constraint_name = tblAll.constraint_name

inner join information_schema.constraint_column_usage tblFK on

tblAllFK.constraint_name=tblFK.constraint_name

Enjoy coding…..

ASP.NET Gridview: Merging Cells

Posted by: viralsarvaiya on: November 4, 2009

I had been searching for a way to merge cells in a GridView

If e.Row.DataItemIndex % 2 = 0 Then
e.Row.Cells(0).RowSpan = 2
e.Row.Cells(1).RowSpan = 2
End If
‘Remove the extra cells created due to row span for odd rows
If e.Row.DataItemIndex % 2 = 1 Then
e.Row.Cells.RemoveAt(0)
e.Row.Cells.RemoveAt(0)
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
End If

This code should take every cell in the first and second columns and merge it with the cell directly below it. Of course, this should be used very carefully, because you could screw up your data if each record does not have another corresponding record with it. However, this shouldn’t be too difficult to program around by adding data checks.

Retrieving Data as XML from SQL Server

Posted by: viralsarvaiya on: November 2, 2009

All the hype that once surrounded XML is finally starting to die down, and developers are really beginning to harness the power and flexibility of the language. XML is a data descriptive language that uses a set of user-defined tags to describe data in a hierarchically-structured format.

The release of Microsoft SQL Server 2000 a couple of months ago saw Microsoft jump on the XML band-wagon too – they’ve included a number of different ways to manipulate data as well-formed XML. Firstly, there’s the SQL XML support. Microsoft’s implementation of SQL XML provides a simple configuration tools that allows developers to gain remote access to databases using URL based queries over HTTP. For example, we can setup an SQL XML virtual directory on our Web server named “myVirtual”. Then, assuming we have the appropriate security permissions, we can use any browser to query our database using a simple URL based query (such as: http://www.myserver.com/myVirtual?SQL=select+*+from+products+for+xml+auto). This then returns our results as an XML based recordset.

Notice the “for xml auto” part of our query above? This determines the way in which SQL Server 2000 shapes our data. There are three shaping methods:

1. “for xml auto”: Returns XML elements that are nested, based on which tables are listed in the “from” part of the query, and which fields are listed in the “select” part.

2. “for xml raw”: Returns XML elements with the “row” prefix (ex: “<row tProduct …>”). Each column in a table is represented as an attribute and null column values aren’t included.

3. “for xml explicit”: Explicit mode is the most complex shaping method used in SQL Server 2000. It allows users to query a data source in such a way that the names and values of the returned XML are specified before the query batch is executed.

for read detials click here

other links…

http://msdn.microsoft.com/en-us/library/ms345137%28SQL.90%29.aspx

http://www.15seconds.com/issue/001102.htm

Export GridView Data into CSVFile In Asp.net

Posted by: viralsarvaiya on: October 30, 2009

Steps.

1) Create Simple Web Application.

2) put the below control in to the page (.aspx)

2.1) GridView (id= GridView1)

2.2) Button (id=button1 and Text =Create CSV File)

3) assign data source to GridView

4) on the button_click event put the following code.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
‘Create CSV file
Dim objSw As New StreamWriter(Server.MapPath(“~/demo.csv”))
‘get table from GridView1
Dim objDt As DataTable = DirectCast(GridView1.DataSource, DataSet).Tables(0)
‘Get No Of Column in GridView
Dim NoOfColumn As Integer = objDt.Columns.Count
‘Create Header
For i As Integer = 0 To NoOfColumn – 1
objSw.Write(objDt.Columns(i))
‘check not last column
If i < NoOfColumn – 1 Then
objSw.Write(“,”)
End If
Next
objSw.Write(objSw.NewLine)
‘Create Data
For Each dr As DataRow In objDt.Rows
For i As Integer = 0 To NoOfColumn – 1
objSw.Write(dr(i).ToString())

If i < NoOfColumn – 1 Then
objSw.Write(“,”)
End If
Next
objSw.Write(objSw.NewLine)
Next
objSw.Close()
Catch ex As Exception
Response.Write(“Can Not Generate CSV File”)
End Try
End Sub

Enjoy Coding….

How to Get Mouse Coordinates with Javascript

Posted by: viralsarvaiya on: October 29, 2009

This will find X and Y coordinates of the mouse where the mouse moves in browser.

<html>
<head>
<title>Get Mouse Coordinates</title>
<script language=”javascript”>
var divObj;

document.onmousemove=getMouseCoordinates;

function getMouseCoordinates(event)
{
ev = event || window.event;
divObj.innerHTML = “Mouse X:”+ev.pageX + ” Mouse Y:”+ev.pageY;
}

function loadDiv()
{
divObj = document.getElementById(“mouseCoord”);
}
</script>
</head>

<body onLoad=”loadDiv()”>
<div id=”mouseCoord”>Mouse Coordinates position will be displayed here.
</div>
</body>
</html>

Get CheckBoxList values using Javascript

Posted by: viralsarvaiya on: October 28, 2009

I have one CheckBoxList control that binds values at runtime from the database, and when I click on a button from the page, I want to get the values (Database Primary Key) from the CheckBoxList, but for the checked checkboxes only.

Here is the code, what I have achieved so far. This code works fine with IE 7, but I am not sure with the FireFox.

ASPX page: <asp:CheckBoxList ID=”CheckBoxList1″ runat=”server” OnDataBound=”CheckBoxList1_DataBound” >
<asp:ListItem Value=”First1″ Text=”First” ></asp:ListItem>
<asp:ListItem Value=”second2″ Text=”Second”></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
<script language=”javascript” type=”text/javascript”>
function CheckItem()
{
var tbl = document.getElementById(‘<%= CheckBoxList1.ClientID %>’).childNodes[0];
for(var i=0; i<tbl.childNodes.length;i++)
{
for(var k=0; k<tbl.childNodes[i].childNodes.length; k++)
{
if(tbl.childNodes[i].childNodes[k].nodeName == “TD”)
{
var currentTD = tbl.childNodes[i].childNodes[k];
for(var j=0; j<currentTD.childNodes.length; j++)
{
if(currentTD.childNodes[j].nodeName == “SPAN”)
{
var currentSpan = currentTD.childNodes[j];
for(var l=0; l<currentSpan.childNodes.length; l++)
{
if(currentSpan.childNodes[l].nodeName == “INPUT” && currentSpan.childNodes[l].type == “checkbox”)
{
var currentChkBox = currentSpan.childNodes[l];
if(currentChkBox.checked)
{
alert(currentSpan.alt);
}
}
}
}
}
}
}
}
}
</script>
Code Behind:

Button1.Attributes.Add(“onclick”, “javascript:CheckItem();”);
CheckBoxList1.DataSource = <Your Dataset>;
CheckBoxList1.DataTextField = “PersonName”;
CheckBoxList1.DataValueField = “PersonID”;
CheckBoxList1.DataBind();
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
CheckBoxList chkList = (CheckBoxList)(sender);
foreach (ListItem item in chkList.Items)
{
item.Attributes.Add(“alt”, item.Value);
}
}

 

other way is as below….

this is run in FF as well as FF

function CheckItem() {

var tbl = document.getElementById(‘<%= CheckBoxList1.ClientID %>’);

var chkspecialCount = tbl.getElementsByTagName(“input”);

var chkspeciallbls = tbl.getElementsByTagName(“label”);

for (var i = 0; i < chkspecialCount.length; i++) {

if (chkspecialCount[i].checked == true) {

var str = chkspeciallbls[i].innerHTML;

alert(str);

}

}

}

Enjoy Coding….

Reference

http://hspinfo.wordpress.com/2008/08/14/get-checkboxlist-values-using-javascript/

Show Div tag in middle of the page with javascript

Posted by: viralsarvaiya on: October 27, 2009

take a element of Div

<div id=”contentmsg” style=”position: absolute; right:25%; width: 100px; height:100px;visibility: hidden;”>
<img src=”images/loading.gif” width=”50px” height=”50px” />
</div>

suppose we have a dropdown and according to onchange() event this div is visible or hide,

<asp:DropDownList ID=”ddlparavalue” runat=”server”></asp:DropDownList>

in the server side bind the dropdownlist dynamically and add the attribultes as below

ddlparavalue.Attributes.Add(“onchange”, “javascript:void HideOrVisibleDDL();”)

in the head of the html section write the following code

<script language=”javascript” type=”text/javascript”>
function HideOrVisibleDDL() {

var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
var IpopTop = ((windowHeight – document.getElementById(“contentmsg”).offsetHeight) / 2);

document.getElementById(“contentmsg”).style.top = IpopTop + document.body.scrollTop;
document.getElementById(“contentmsg”).style.left = (document.body.clientWidth / 2) – 50;

document.getElementById(“contentmsg”).style.visibility = “visible”;

}
</script>

in some case it is not working just becouse of the DOCType tag so please remove the DOCTYPE tag as like below

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

so remove this tag.

enjoy coding….

Ajax Update panel in asp.net

Posted by: viralsarvaiya on: October 26, 2009

What ist the UpdatePanel in ASP.NET Ajax? The answer is easy: When adding an UpdatePanel-control to your page, you can achieve a partial-update of your page on a postback. Only the content in the UpdatePanel is refreshed, the other parts of the page remain unchanged. This topic explains, how you can setup an Ajax-enabled project and use the UpdatePanel control.

for more details click below….

http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx

http://www.codegod.de/WebAppCodeGod/UpdatePanel-tutorial-ASP-NET-AJAX-AID281.aspx

Blog Stats

  • 4,113 hits