Проблема была в том, что я посылал Cookie, но не принимал их, работающий код:
public class SpaceTrackConnection
{
public SpaceTrackConnection()
{
client.Encoding = Encoding.UTF8;
}
public bool login(string login, string password)
{
try{
logout();
}
catch { }
var data = new NameValueCollection
{
{ "identity", login },
{ "password", password },
};
byte[] response;
try{
response = client.UploadValues(uriBase + "auth/login", "POST", data);
}
catch{
return false;
}
var responseText = Encoding.UTF8.GetString(response);
responseText.ToLowerInvariant();
return responseText == "\"\"";
}
public void logout()
{
var tmp = client.DownloadData(uriBase + "ajaxauth/logout");
}
public string sendReqest(string request)
{
return Encoding.UTF8.GetString(client.DownloadData(uriBase + request));
}
public class WebClientEx : WebClient
{
// Create the container to hold all Cookie objects
private CookieContainer m_cookieContainer = new CookieContainer();
// Override the WebRequest method so we can store the cookie
// container as an attribute of the Web Request object
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
var httpRequest = request as HttpWebRequest;
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
httpRequest.Proxy = WebProxy.GetDefaultProxy();
httpRequest.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
httpRequest.CookieContainer = m_cookieContainer;
}
return request;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
var tmp = base.GetWebResponse(request);
if( tmp is HttpWebResponse)
{
var resopnse = tmp as HttpWebResponse;
m_cookieContainer.Add(resopnse.Cookies);
}
return tmp;
}
} // END WebClient Class
WebClientEx client = new WebClientEx();
string uriBase = "https://www.space-track.org/";
}