1

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=;
SAT
  • 647
  • 1
  • 12
  • 23
Peter J
  • 11
  • 2

2 Answers2

1

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.

Community
  • 1
  • 1
cii
  • 155
  • 2
  • 12
0

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!)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • It is that very API I'm trying to interact with, and in the docomentation of the API it refers to the content as being application/json as I have used, hence the question what other, probably silly, mistake I've done? – Peter J Mar 26 '14 at 12:23
  • @PeterJ - I suggest you either use Java, or contact Sony and ask them for advice. – Stephen C Mar 26 '14 at 14:47
  • That comment made a bit of a catch 22 situation:) The Sony Developers site relies on StackOverflow as their support channel. Perhaps someone from Sony eventually will read this conversation and come up with an answer. – Peter J Mar 26 '14 at 15:02
  • @PeterJ - And if someone at Sony is listening, maybe they take a hint ... and DOCUMENT the wire protocol, so that customers are not tempted / forced to reverse engineer it. – Stephen C Mar 26 '14 at 15:11