0

At first I send token and password to my php api script. After compiling and checking my api script, if the result matches in the database, it returns me a cookie. I want to import it in my site opened in Selenium. Error is enter image description here

example of a part of a cookie:

[{"domain":"www.googleadservices.com","expires":1692908312.1913769,"httpOnly":false,"name":"Conversion","path":"/pagead/conversion/992760409/","priority":"Medium","sameParty":false,"sameSite":"None","secure":true,"session":false,"size":152,"sourcePort":443,"sourceScheme":"Secure","value":"EgwIABUAAAAAHQAAAAAYASDWjO_3nfnOu4gBSAFqN0VBSWFJUW9iQ2hNSTVvV3VpLWVUX3dJVlVvalZDaDJQSGdZbUVBQVlBU0FBRWdMelZfRF9Cd0VwvsrQhueT_wKQAanRhrSVEJgBAA"}]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using SeleniumUndetectedChromeDriver;
using System.Net.Http;
using SeleniumExtras.WaitHelpers;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium.Support.UI;
using Newtonsoft.Json;


if(token.Length == 18)
            {
                string url = "/api/token_script.php";
                using (HttpClient client = new HttpClient())
                {
                    var data = new MultipartFormDataContent
                    {
                        {new StringContent("97xUaJzUeNNY9nLoFOdS5MxkYidyiTMi6a1R8zvOjiWYBSCgNQeyR6OvApt2"),"password" },
                        {new StringContent(token),"token" },
                    };

                    HttpResponseMessage response = await client.PostAsync(url, data);

                    if (response.IsSuccessStatusCode)
                    {
                        button1.Visible = false;
                        string responseBody = await response.Content.ReadAsStringAsync();
                        string mycookie = @responseBody;
                        MessageBox.Show(mycookie);

                        using (var driver = UndetectedChromeDriver.Create(
                        driverExecutablePath: @"C:\Users\sdjas\Desktop\chromedriver-win32\chromedriver.exe"))
                        {



                           
                            driver.GoToUrl("https://www.google.com");
                            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
                            driver.Manage().Cookies.AddCookie(new Cookie(mycookie));
                            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(600));
                            driver.Quit();
                        }










                    }
                    else
                    {
                        Console.WriteLine("Error Code: " + response.StatusCode);
                    }
                }
            }
            else if(token.Length > 0) {
                MessageBox.Show("Please enter correct token.");
            }
            else
            {
                MessageBox.Show("Please Enter Token.");
            }

Adding the cooki obtained from my php script to my browser opened with selenium library in c#

Shadow
  • 33,525
  • 10
  • 51
  • 64
Sytehel
  • 1
  • 1
  • The cookie could be expired. What status code are you getting in the response? Should be getting 200 OK or 400/500 error. – jdweng Aug 21 '23 at 12:16
  • @jdweng I don't think the cookie has expired, the problem is already in the line that appears in the screenshot, I want to import the cookie information I obtained from php to the browser. – Sytehel Aug 21 '23 at 20:10
  • See the JWT Key here : https://stackoverflow.com/questions/73658327/how-to-implement-oauth2-0-authentication-token-in-asp-net-core-web-api – jdweng Aug 21 '23 at 23:21

0 Answers0