I have a project that uses the hockeystreams.com API. I am having trouble with using their API to login from my WinForm. It always gives me a blank response, whether I give a bad username/password combination or a correct one. My code is as follows:
public static bool LogIn(string username, string password)
{
string URL = string.Format("{0}&username={1}&password={2}", Global.LOGIN_API, username, password);
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
webRequest.ContentType = "application/json; charset=utf-8";
webRequest.Accept = "application/json, text/javascript, */*";
webRequest.Method = "POST";
try
{
WebResponse response = webRequest.GetResponse();
Stream stream = response.GetResponseStream();
string json = "";
using (StreamReader reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
json += reader.ReadLine();
}
}
LogInJSON deserializedLogInData = JsonConvert.DeserializeObject<LogInJSON>(json);
if (deserializedLogInData.Status == "Success")
{
Global.TOKEN = deserializedLogInData.Token;
Global.USERNAME = deserializedLogInData.Username;
Global.ISPREMIUM = deserializedLogInData.Membership == "REGULAR" ? false : true;
Global.FAVORITETEAM = deserializedLogInData.Favteam;
return true;
}
else
{
return false;
}
}
I have tried changing the POST to PUT, but that throws a 406 error (Bad Request). I am very green with JSON so I don't know where to go from here. Any help greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire