Jump to content

Webui API Problems - Invalid Request


camrymps

Recommended Posts

Hi everyone! I am having some issues with the Webui API. I am kind of a noob at this stuff so please stick with me. I am trying to make a web app that lets me search for movies I want to download and have it download them via the uTorrent Webui. I basically have the web app working (in PHP), but for some reason I can't send the movie torrent hashes to the Webui to start downloading the movies. I think I have everything set up correctly. I have Webui enabled through uTorrent and I am using the default port of 8080. I am able to successfully see the Webui without any problems. However, I am not able to access it remotely via my external IP address, but that I will attempt to figure out later. I have an example of the type of requests I am trying to create:

http://[my_username]:[my_password]@localhost:8080/gui/?token=CeTxzBAnwoR_d7WMxVQ4hlvvjIQzoHUbu6uHo-C7QvNl8AjIQdf0bLdg21IAAAAA&action=start&hash=af7ed5f48a2a035447ce0afd0ceb372484165588

As far as I know, I do not think that this request is incorrect. I get the token from the gui/token.html file and have it inserted into the request via a PHP script. The token is inserted only when the token expires (or when the request is invalid), but the request is supposedly invalid every time. I am just really confused as to why this is happening. Please help!

Link to comment
Share on other sites

  • 1 month later...

Not sure if you've gotten any help on this yet but Kitsoran is probably right. When you call token.html there is a GUID in the response headers that needs to be extracted and used as a cookie for any subsequent calls from that session. This is how I do it in my custom VB console app:

 

  • TURI is the base URI of http://localhost:<port>/gui
  • utToken and utCookieCont are private variables in my WebUiCaller class which retain the hash and cookie data for my session and I simply pass around the WebUiCaller object when making calls to the WebUI API.

 

Probably isn't the best way to do it but it works. Also, it's less secure (and no recommended) but you can always just set webui.token_auth to false in the advanced setting in the uTorrent client and not pass the hash at all.

Private Sub getKeyToken()        ' Create Token URI        Dim tokUri As New Uri(TURI)        tokUri = New Uri(tokUri, TAction.GetToken)        ' Create HTTP Request from URI        Dim torRequest As HttpWebRequest = HttpWebRequest.Create(tokUri)        torRequest.KeepAlive = False        ' Create Credentials         Dim torCreds As New CredentialCache        torCreds.Add(tokUri, "Basic", New NetworkCredential(UIUSR, UIPSW))        ' Assign Credentials to Request and define Content-Type and Method        torRequest.Credentials = torCreds        torRequest.Method = "GET"        ' Create HTTP Response and collect response        Dim torResponse As HttpWebResponse = CType(torRequest.GetResponse(), HttpWebResponse)        ' Extract cookie from header data        Dim cookieArray As String() = Split(torResponse.GetResponseHeader("Set-Cookie"), ";")        Dim cookieguid As String = Right(cookieArray(0), cookieArray(0).Length - InStr(cookieArray(0), "="))        Dim cookiepath As String = Right(cookieArray(1), cookieArray(1).Length - InStr(cookieArray(1), "="))        utCookieCont.Add(New Cookie("GUID", cookieguid, cookiepath, tokUri.Host))        ' Read response stream into HTML document        Dim tokDoc As New HtmlDocument        tokDoc.Load(New StreamReader(torResponse.GetResponseStream))        ' Extract token from HTML document object        utToken = tokDoc.GetElementbyId("token").InnerText    End Sub
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...