2011-06-13, 03:35
I'm having some issues getting Newzbin support built into Audio-Matic. The API documentation (http://docs.newzbin.com/index.php/Main_Page) is pretty sparse and I was hoping some of you might be able to help.
I can search for reports just fine (using ReportFind url) and I get the expected results, but using pretty much the same code I'm getting a 400 (Bad Request) response no matter what I try when I attempt to download an nzb file (using DirectNZB url) or when I try to get report details (using ReportInfo url).
Here is the VB .Net code that I'm using:
I can search for reports just fine (using ReportFind url) and I get the expected results, but using pretty much the same code I'm getting a 400 (Bad Request) response no matter what I try when I attempt to download an nzb file (using DirectNZB url) or when I try to get report details (using ReportInfo url).
Here is the VB .Net code that I'm using:
Code:
Public Sub Newzbin_GetNZBfile(ByVal reportID As String)
Dim strURL, strOutput As String
Dim NZBresults() As String
Dim responseHeaders() As String
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
'API url
strURL = "http://www.newzbin.com/api/dnzb/"
Try
' Create a request using a URL that can receive a post.
request = WebRequest.Create(strURL)
' Set the Method property of the request to POST.
request.Method = "POST"
' Create POST data and convert it to a byte array.
Dim postData As String = "username=" & NEWZBIN_USER & "&password=" & NEWZBIN_PASS & "&reportid=" & reportID
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
' Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded"
' Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As Stream = request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
response = request.GetResponse()
' Display the status.
writeLog("Newzbin STATUS: " & response.StatusCode)
' Get the stream containing content returned by the server.
dataStream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
reader = New StreamReader(dataStream)
' Read the content.
strOutput = reader.ReadToEnd()
responseHeaders = response.Headers.ToString.Split(vbNewLine)
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
Catch ex As Exception
MsgBox("Error connecting to Newzbin." & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, "Newzbin Connection Problem")
writeLog("ERROR: fetchDownloads(Newzbin) - Error connecting to Newzbin. " & ex.Message)
Finally
If Not response Is Nothing Then response.Close()
End Try
End Sub