mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 17:27:59 +00:00
Fixed XBMC JSON requests.
This commit is contained in:
parent
4eea6b8c6b
commit
5f0a95b2b1
3 changed files with 43 additions and 16 deletions
|
@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test
|
|||
public class XbmcProviderTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void JsonEror_true()
|
||||
public void JsonError_true()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
|
@ -36,7 +36,21 @@ public void JsonEror_true()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void JsonEror_false()
|
||||
public void JsonError_true_empty_response()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
var response = String.Empty;
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<XbmcProvider>().CheckForJsonError(response);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(true, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonError_false()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
|
|
|
@ -74,24 +74,31 @@ public virtual string PostCommand(string address, string username, string passwo
|
|||
|
||||
byte[] byteArray = Encoding.ASCII.GetBytes(command);
|
||||
|
||||
var request = WebRequest.Create(address);
|
||||
var request = (HttpWebRequest)WebRequest.Create(address);
|
||||
request.Method = "POST";
|
||||
request.Credentials = new NetworkCredential(username, password);
|
||||
request.ContentLength = byteArray.Length;
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
var dataStream = request.GetRequestStream();
|
||||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||||
dataStream.Close();
|
||||
request.ContentType = "application/json";
|
||||
request.Timeout = 2000;
|
||||
request.KeepAlive = false;
|
||||
|
||||
var response = request.GetResponse();
|
||||
dataStream = response.GetResponseStream();
|
||||
var reader = new StreamReader(dataStream);
|
||||
// Read the content.
|
||||
string responseFromServer = reader.ReadToEnd();
|
||||
//Used to hold the JSON response
|
||||
string responseFromServer;
|
||||
|
||||
reader.Close();
|
||||
dataStream.Close();
|
||||
response.Close();
|
||||
using (var requestStream = request.GetRequestStream())
|
||||
{
|
||||
requestStream.Write(byteArray, 0, byteArray.Length);
|
||||
|
||||
using (var response = request.GetResponse())
|
||||
{
|
||||
using (var responseStream = response.GetResponseStream())
|
||||
{
|
||||
using (var reader = new StreamReader(responseStream))
|
||||
{
|
||||
responseFromServer = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return responseFromServer.Replace(" ", " ");
|
||||
}
|
||||
|
|
|
@ -300,6 +300,12 @@ public virtual bool CheckForJsonError(string response)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(response))
|
||||
{
|
||||
Logger.Debug("Invalid response from XBMC, the response is not valid JSON");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue