gaurav sharma

gaurav sharma

  • NA
  • 1
  • 39.6k

The remote server returned an error: (401) Unauthorized.

May 21 2015 8:03 AM
while i am running my c# code then i am getting this error here is my code below
var postBody = "screen_name=" + Uri.EscapeDataString(screen_name) + "&count=" + Uri.EscapeDataString(notweets);//
resource_url += "?" + postBody;
byte[] postDataEncoded = System.Text.Encoding.UTF8.GetBytes(authHeader);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
request.Accept = "application/xml";
request.Headers.Add("Authorization", authHeader);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataEncoded.Length;


WebResponse response = request.GetResponse();
string responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();
context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(responseData));
context.Response.End(); 

Answers (2)