[英]Connect to json-rpc interface
我正在嘗試通過C#/ Java連接到傳輸rpc接口,以獲取一些信息。 https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt不幸的是,我在獲取正確的HTTP-Post訪問接口時遇到問題。 例如,如果我在C#中嘗試此操作:
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["torrent-get"] = "id";
var response = client.UploadValues("http://ip:9091/transmission/rpc", values);
var responseString = Encoding.Default.GetString(response);
Console.WriteLine("" + responseString);
}
或者,如果我使用:
using (var webClient = new WebClient())
{
String json = "{\"arguments\": {\"fields\": [ \"id\", \"name\", \"totalSize\" ],\"ids\": [ 7, 10 ]},\"method\": \"torrent-get\",\"tag\": 39693}";
var response = webClient.UploadString("http://192.168.240.171:9091/transmission/rpc", "POST", json);
Console.WriteLine(""+response);
}
我收到以下錯誤:
System.dll中發生了類型為'System.Net.WebException'的未處理異常。其他信息:Remoteserver返回異常:(409)沖突。
你必須保存在409響應中提供X-傳輸會話Id並重新提交了X-傳輸會話Id屬性的請求添加到您的請求頭。
java中的示例:
int index = responseString.indexOf("X-Transmission-Session-Id:");
String sessionId = responseString.substring(index + 27, index + 75);
connection.setRequestProperty("X-Transmission-Session-Id", sessionId);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.