system.net.webexception ASP.NET

sthapatiinfo
After user enters login information with answers etc....it redirects to correct URL and we have posted back api+token+secret SHA256 but it gives following error...
System.Net.WebException The Remote Server Returned 403 Forbidden
  • Kailash
    Please share the exact parameters you are sending and the JSON error response you're getting.
  • sthapatiinfo
    here is the complete code in asp.net, here you go..

    public void Authenticationtemp()
    {
    string url = "https://api.kite.trade/session/token";
    var postData = "api_key=" + apikey + "&request_token=" + rqtoken + "&checksum=" + checksum;

    byte[] data = Encoding.UTF8.GetBytes(postData);// Encoding.ASCII.GetBytes(postData);

    lbl3.Text = url;
    try
    {

    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.ContentType = "application/json; charset=UTF-8";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
    stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();

    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
    Response.Write(responseString);
    }
    catch (Exception ex)
    {
    Response.Write(ex);
    }
    }
  • sthapatiinfo
    in above code GetResponseStream giving 403 forbidden. Let us know when we are making mistake..thanks
  • Kailash
    How are you computing the checksum? Can you share that bit?
  • sthapatiinfo
    Yes,
    public void sha256_hash()
    {
    string value = apikey + rqtoken + apisecretkey;
    StringBuilder Sb = new StringBuilder();

    using (SHA256 hash = SHA256Managed.Create())
    {
    Encoding enc = Encoding.UTF8;
    Byte[] result = hash.ComputeHash(enc.GetBytes(value));

    foreach (Byte b in result)
    Sb.Append(b.ToString("x2"));
    }

    checksum = Sb.ToString();
    }
  • Kailash
    @sthapatiinfo Your app is 'Publisher' which doesn't support APIs. You should create a "Connect" app.
Sign In or Register to comment.