Erro 415 Unsupported media type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ernildo1
    Junior Member
    • Apr 2012
    • 6

    #1

    Erro 415 Unsupported media type

    Erro 415 Unsupported media type

    I receiver this error,
    can anybody help me?
  • BetfairDeveloperProgram
    Administrator
    • Oct 2008
    • 680

    #2
    Hi Ernildo1

    Please check that your sending the required Accept: application/json header with your API requests.

    Thanks

    Neil

    Comment

    • Ernildo1
      Junior Member
      • Apr 2012
      • 6

      #3
      Hello


      I send this required in all conection :



      request.setRequestHeader("X-Application", this._APP_KEY)
      request.setRequestHeader("content-type", 'application/json')
      request.setRequestHeader("Accept", 'application/json')
      request.setRequestHeader("X-Authentication", this._SESSION_TOKEN)


      but sometimes I get the error 415





      Thank you for reply me.

      Comment

      • jabe
        Senior Member
        • Dec 2014
        • 705

        #4
        I don't know which language you are using, but the mixture of single and double quotes within your brackets looks odd.

        As well as that, I believe you need colons after X-Application and X-Authorisation.

        Try this:

        request.setRequestHeader("content-type", "application/json")
        request.setRequestHeader("Accept", "application/json")
        request.setRequestHeader("X-Authentication:", this._SESSION_TOKEN)
        request.setRequestHeader("X-Application:", this._APP_KEY)

        Comment

        • Ernildo1
          Junior Member
          • Apr 2012
          • 6

          #5
          Ok thank you for reply me i try this now

          Comment

          • Ernildo1
            Junior Member
            • Apr 2012
            • 6

            #6

            I'm using javascript

            Comment

            • Ernildo1
              Junior Member
              • Apr 2012
              • 6

              #7

              I did what you said and error 415 continues.

              Comment

              • jabe
                Senior Member
                • Dec 2014
                • 705

                #8
                Could you post more of the code? The issue might be elsewhere in your code.

                Comment

                • Ernildo1
                  Junior Member
                  • Apr 2012
                  • 6

                  #9
                  The application run javascript code in electron js, we have a class where a method "send" return a request as a javascript promise using XMLHttpRequest, like this:
                  Code:
                  send(url, data = "", method = "POST", headers = true, callback = (request, context) => {return request}, noCache = false)
                  {
                  let self = this;
                  let request = new XMLHttpRequest()
                  return new Promise((resolve, reject) => {
                  request.open(method, url, true)
                  if(headers){
                  self.setHeaders(request)
                  }
                  self.setCache(request, noCache)
                  request = callback(request, self)
                  request.onreadystatechange = () => {
                  if(request.readyState == XMLHttpRequest.DONE && request.status == 200){
                  resolve(request.responseText)
                  }else if(request.status === 0 || request.status >= 400){
                  reject({status: request.status, statusText: request.statusText})
                  }
                  }
                  request.onerror = () => {
                  reject({status: request.status, statusText: request.statusText})
                  }
                  request.send(data)
                  })
                  }

                  Comment

                  • jabe
                    Senior Member
                    • Dec 2014
                    • 705

                    #10
                    I'm going to post some of the code I've been using. Much of it was originally found on this forum and in other places, but, alas, it was so long ago that I can't recall exactly, so can't credit the source.

                    I hope it will give you the clues you need to fix your code.

                    This is a call to a routine that sends bet-related request calls to Betfair:

                    Code:
                     Public Function API_listCompetitions()
                            ' From Initialise
                            Return API_sendBetReq("listCompetitions", """filter"":{ }")
                        End Function
                    This is the routine that sets up and makes the call to Betfair (note: this works most of the time but the error trapping needs attention):

                    Code:
                     Public Function API_sendBetReq(ByVal method As String, ByVal params As String)
                    
                            Dim request As WebRequest = WebRequest.Create("https://api.betfair.com/exchange/betting/json-rpc/v1/")
                    
                            Dim postData As String = "{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/" & method & """, ""params"": {" & params & "},""id"": 1}"
                    
                            Dim JSONByteData As Byte() = Encoding.UTF8.GetBytes(postData)
                    
                            request.Method = "POST"
                            request.ContentType = "application/json-rpc"
                            request.ContentLength = JSONByteData.Length
                            request.Headers.Add("X-Application: " & appKey)
                            request.Headers.Add("X-Authentication: " & ssoid)
                            request.Headers.Add("Content-Encoding: gzip")
                    
                    
                            Dim dataStream As Stream = Nothing
                    
                            dataStream = request.GetRequestStream()
                            dataStream.Write(JSONByteData, 0, JSONByteData.Length)
                    
                            Dim response As WebResponse = Nothing
                            Dim responseFromServer As String = ""
                            Try
                                response = request.GetResponse()
                                dataStream = response.GetResponseStream()
                                Dim reader As New StreamReader(dataStream)
                                responseFromServer = reader.ReadToEnd()
                                reader.Close()
                                response.Close()
                            Catch e As WebException
                                MessageBox.Show("Error!")
                            End Try
                    
                            dataStream.Close()
                            Dim x As String = DataFetched(Me, responseFromServer.Length)
                            Return responseFromServer
                        End Function

                    Comment

                    Working...
                    X