我寫了一個小小的C#程序來測試與我的QX100的通信,但無法讓它工作。關於爲什麼我獲得不受支持的媒體類型的任何建議? 以下是來自Fiddler的代碼和一些跟蹤數據。HTTP/1.1 415嘗試在C#中使用Sony Camera Remote API時不支持媒體類型?
謝謝!
代碼:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("mylink");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"method\": \"getAvailableApiList\",\"params\": [],\"id\": 1,\"version\": \"1.0\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine("httpResponse: " + result.ToString());
}
Console.ReadLine();
}
後追蹤:
POST myLink HTTP/1.1
Content-Type: application/json
Host: 10.0.0.1:64321
Content-Length: 71
Expect: 100-continue
Connection: Keep-Alive
{"method": "getAvailableApiList","params": [],"id": 1,"version": "1.0"}
Respons追蹤:
HTTP/1.1 415 Unsupported Media Type
Connection: close
Date: Wed, 26 Mar 2014 07:45:13 GMT
Server: UPnP/1.0 SonyImagingDevice/1.0
X-AV-Server-Info: av=5.0; hn=""; cn="Sony Corporation"; mn="SonyImagingDevice"; mv="1.0";
X-AV-Physical-Unit-Info: pa=""; pl=;
正是我非常想要與之交互的API,並且在API的docomentation中,它將內容稱爲應用程序/ json,因爲我已經使用過,因此問題還有什麼,可能很愚蠢,做過了嗎? –
@PeterJ - 我建議你要麼使用Java,要麼聯繫索尼,並要求他們提供建議。 –
該評論引起了一些爭議22情況:)索尼開發者網站依靠StackOverflow作爲他們的支持渠道。也許索尼的某個人最終會讀到這個對話並提出一個答案。 –