Peter J
Peter J

Reputation: 11

HTTP/1.1 415 Unsupported Media Type when trying to use Sony Camera Remote API in C#?

I have written a small C# program to test the communication with my QX100 but can't get it to work. Any suggestions as to why I get the Unsupported media type? Below is the code and some trace data from Fiddler.

Thanks!

Code:

        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 traced:

 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 traced:

  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=;

Upvotes: 1

Views: 1150

Answers (2)

cii
cii

Reputation: 153

I realize this is an old question, but it turns up in google, so I thought I'd post the solution I found for future generations.

According to the Sony API reference and this post , the camera doesn't listen on that port for API calls. That is the port for SSDP responses and GET requests for the API description file. If you send this GET request,

GET /DmsRmtDesc.xml HTTP/1.1
Host: 10.0.0.1
Accept: */*
Connection: close

Then you'll find the API returns an xml file with this line

<av:X_ScalarWebAPI_ActionList_URL>http://10.0.0.1:10000/sony</av:X_ScalarWebAPI_ActionList_URL>

All POST requests need to be sent to that IP and port, for me that was 10000. The 415 response is correct because that port doesn't do API calls. I spent far too long trying to figure this out, so I hope it helps someone.

Upvotes: 1

Stephen C
Stephen C

Reputation: 719551

That status code means that you sent a request to the device with a content type that it did not expect, or does not understand.

The problem is that there doesn't appear to be any documentation for the using Sony cameras directly, so it is not obvious what you should be sending. But there is an alternative. Sony have made available an SDK for the Java Camera APIs. You can download the SDK from this page.

This is not much help for people trying to access a camera using C#, and note that the click-through license for the SDK requires you to not reverse engineer the SDK, and so on. (Read it carefully!)

Upvotes: 0

Related Questions