JSON запросы к сайту Qiwi-кошелька - C#
Формулировка задачи:
Всем привет, дорогие, это моя первая тема, прошу не судить строго.
Хотелось узнать что я делаю не так при авторизации в киви кошельке со своей программы, код будет ниже.
Как я понял, здесь используется JSON его вполне получилось имитировать, но авторизации нету.
Используется библиотека xNet, при компиляции ошибок не было
на всякий случай
public string Test(string login, string pass)
{
CookieContainer QiwiCook = new CookieContainer();
string mony = "";
{
string data = "{\"login\":\""+login+"\",\"password\":\""+pass+"\"}";
string ticket = "";
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://qiwi.com/");
request.CookieContainer = QiwiCook;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
//https://qiwi.com/
}
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://auth.qiwi.com/cas/tgts");
request.Method = "POST";
request.CookieContainer = QiwiCook;
request.ContentType = "application/json; charset=utf-8";
string sQueryString = data;
byte[] ByteArr = Encoding.ASCII.GetBytes(sQueryString);
request.ContentLength = ByteArr.Length;
request.GetRequestStream().Write(ByteArr, 0, ByteArr.Length);
string html = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = myStreamReader.ReadToEnd();
ticket = html.Substring("ticket\":\"", "\"");
}
}
}
{
string Security = "{\"ticket\":\"" + ticket + "\",\"service\":\"https://qiwi.com/j_spring_cas_security_check\"}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://auth.qiwi.com/cas/sts");
request.Method = "POST";
request.CookieContainer = QiwiCook;
request.ContentType = "application/json; charset=utf-8";
string sQueryString = Security;
byte[] ByteArr = Encoding.ASCII.GetBytes(sQueryString);
request.ContentLength = ByteArr.Length;
request.GetRequestStream().Write(ByteArr, 0, ByteArr.Length);
string html = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = myStreamReader.ReadToEnd();
}
}
}
{
string Security = "{\"service\":\"https://qiwi.com/j_spring_cas_security_check\",\"ticket\":\"" + ticket + "\"}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://auth.qiwi.com/cas/sts");
request.Method = "POST";
request.CookieContainer = QiwiCook;
request.ContentType = "application/json; charset=utf-8";
string sQueryString = Security;
byte[] ByteArr = Encoding.ASCII.GetBytes(sQueryString);
request.ContentLength = ByteArr.Length;
request.GetRequestStream().Write(ByteArr, 0, ByteArr.Length);
string html = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = myStreamReader.ReadToEnd();
ticket = html.Substring("\":\"", "\"");
}
}
}
{
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://auth.qiwi.com/cas/sts");
// request.CookieContainer = QiwiCook;
request.Method = "GET";
request.ContentType = "application/json;charset=UTF-8";
// request.ContentType = "application/json;charset=UTF-8";
WebResponse response = request.GetResponse();
string html = response.ToString();
}
//OPTIONS
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://qiwi.com/j_spring_cas_security_check?ticket=" + ticket);
request.CookieContainer = QiwiCook;
request.Method = "GET";
// request.AllowAutoRedirect = false;
request.ContentType = "application/json;charset=UTF-8";
WebResponse response = request.GetResponse();
string html = response.ToString();
}
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://qiwi.com/main.action");
request.CookieContainer = QiwiCook;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
string html = response.ToString();
mony = html.Substring("<div class=\"account_current_amount\">", "<");
}
}
}using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using xNet.Net; using xNet.Text; using System.IO; using System.Net;
Решение задачи: «JSON запросы к сайту Qiwi-кошелька»
textual
Листинг программы
{"code":{"value":"0","_name":"NORMAL"},"data":{"balances":{"RUB":1.01},"handledCardCount":0,"linkedCardCount":0,"messages":5,"person":"затёр","unpaidOrderCount":0,"validSession":true,"webmoneyHandledLinksCount":0,"webmoneyLinksCount":0},"message":null,"messages":null}