please look at the below code. please tell me where am going wrong.
Purpose: just trying to access a web api method and retrieving data.
$('#txtApprovedEmails').keypress(function () {
alert("here ajax method");
$.ajax({
type: "GET",
dataType: "json",
url: 'selectemployees.aspx/GetEmployees',
async: false,
contentType: "application/json; charset=utf-8",
success: function () {
debugger;
alert("success");
}
});
});
[WebMethod(EnableSession = false)]
public static void GetEmployees()
{
string strHeader = ("WRAP access_token=\"client=2d579b88a6940d78d7b5036fc4b5f6a\"");
request.Headers["Authorization"] = strHeader;
request.Method = "GET";
request.Accept = "text/xml";
request.ContentType = "application/xml; charset=utf-8";
request.ContentLength = 0;
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
var encoding = new UTF8Encoding();
string str = "<UserInfo><CompanyName>mj</CompanyName><UserName>mj</UserName><Password>mj</Password></UserInfo>";
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(str);
request.ContentLength = bytes.Length;
using (var writeStream = request.GetRequestStream())
{
StreamWriter swWriter = new StreamWriter(writeStream);
writeStream.Write(bytes, 0, bytes.Length);
}
HttpWebResponse hwrResponse = (HttpWebResponse)request.GetResponse();
Stream strResponse = hwrResponse.GetResponseStream();
StreamReader srReader = new StreamReader(strResponse);
DataSet ds = new DataSet();
// ds = (DataSet)(srReader.ReadToEnd());
string RequestResult = srReader.ReadToEnd();
srReader.Close();
strResponse.Close();
hwrResponse.Close();
}
It is showing "internal server error" in console.