S
@Moderator_3
Hi Team,
This is my code. Let me know what is issue here ?
obj = connect.GenerateSession(Client_code, Password,TOTP);
public OutputBaseClass GenerateSession(string clientcode, string password,string totp)
{
OutputBaseClass res = new OutputBaseClass();
res.status = true;
res.http_code = "200";
try
{
AngelTokenResponse agr = new AngelTokenResponse();
string URL = APIURL + "/rest/auth/angelbroking/user/v1/loginByPassword";
string PostData = "{\"clientcode\":\"" + clientcode + "\",\"password\":\"" + password + "\",\"totp\":\"" + totp + "\"}";
Console.WriteLine("Sumedh...Printing URL and PostData..\n" );
Console.WriteLine(URL + PostData + "After");
string json = POSTWebRequest(null, URL, PostData);
Console.WriteLine(json);
if (!json.Contains("PostError:"))
{
agr = JsonConvert.DeserializeObject<AngelTokenResponse>(json);
res.TokenResponse = agr.data;
res.status = agr.status;
res.http_error = agr.message;
res.http_code = agr.errorcode;
this.Token = agr.data;
}
private string POSTWebRequest(AngelToken agr, string URL, string Data)
{
try
{
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
HttpWebRequest httpWebRequest = null;
httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
if (agr != null)
httpWebRequest.Headers.Add("Authorization", "Bearer " + agr.jwtToken);
httpWebRequest.Headers.Add("X-Content-Type-Options", "nosniff");
httpWebRequest.Headers.Add("X-UserType", USER);
httpWebRequest.Headers.Add("X-SourceID", SourceID);
httpWebRequest.Headers.Add("X-ClientLocalIP", ClientLocalIP);
httpWebRequest.Headers.Add("X-ClientPublicIP", ClientPublicIP);
httpWebRequest.Headers.Add("X-MACAddress", MACAddress);
httpWebRequest.Headers.Add("X-PrivateKey", PrivateKey);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";
byte[] byteArray = Encoding.UTF8.GetBytes(Data);
httpWebRequest.ContentLength = byteArray.Length;
string Json = "";
Stream dataStream = httpWebRequest.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();