HTTP 415 while sending JSON object using POST

前端 未结 2 1512
我在风中等你
我在风中等你 2021-02-12 12:56
import java.io.BufferedReader;    
import java.io.InputStreamReader;    
import java.net.HttpURLConnection;    
import java.net.URL;    
import java.io.DataOutputStream;         


        
相关标签:
2条回答
  • 2021-02-12 13:20

    I was correctly passing

    Content-Type: application/json
    

    But my server was still rejecting the request because I was also passing

    Accept: application/json
    

    Which was not allowed in my case.

    0 讨论(0)
  • 2021-02-12 13:24

    The HTTP response code you get is

    415 Unsupported Media Type
    

    This means that the server can not handle the format you sent to it. Your HTTP request sets this header:

    Content-Type: application/x-www-form-urlencoded
    

    This is the content type sent by a browser if a form is submitted. If you want to send JSON, use this header:

    Content-Type: application/json
    
    0 讨论(0)
提交回复
热议问题