C# ile Web Sitesine Giriş yapıp geriye bir Json yanıtı alıyoruz. UserID yi de elde ettik.
Kullanıcıya özel bir sayfada nasıl gezinebiliriz(örn : profil sayfası)?
C# Form App -> Web Sitesinin Session Bilgilerini Kullanmak? (Login Olma) |
7 Mesajlar | 1.296 Okunma |
public string GET(string URL,string at,string userID)
{
cookies = new CookieContainer();
var httpClient = new HttpClient();
ServicePointManager.MaxServicePointIdleTime = 1000;
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12;
string jsonString = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
// var request = new RestRequest(URL, Method.GET);
request.Method = "GET";
request.Credentials = CredentialCache.DefaultCredentials;
// ((HttpWebRequest)request).UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)";
request.Accept = "/";
request.KeepAlive = true;
request.UseDefaultCredentials = true;
request.CookieContainer = new CookieContainer();
httpClient.DefaultRequestHeaders.Clear();
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + at);
//httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", at);
// httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// httpClient.DefaultRequestHeaders.ConnectionClose = true;
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", at);
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
// request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json";
request.Headers["Authorization"] = "Bearer "+at;
request.AllowAutoRedirect = false;
request.CookieContainer.Add(new Cookie("access_token", at, "/", ".auth.trendyol.com"));
request.CookieContainer.Add(new Cookie("COOKIE_TY.Entrance", "x="+userID+"tx="+at, "/", ".trendyol.com"));
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)";
request.Headers["cache-control"] = "no-cache";
WebResponse response = request.GetResponse();
//var response = httpClient.Execute(request);
if (at == null) {
MessageBox.Show("Çerez Parametresi Alınamadı!");
return "Çerez Parametresi Alınamadı!";
}
StreamReader sr = new StreamReader(response.GetResponseStream());
jsonString = sr.ReadToEnd();
sr.Close();
return jsonString;
}