2 qq 28548043 qq_28548043 于 2015.05.28 11:09 提问

http 415错误怎么解决?

public String sendPost(String jsonStr) throws IOException {
String path="http://183.57.42.117:8081/ca/yunxin/risk";
//String path="http://www.baidu.com";
byte[] data = jsonStr.getBytes();

URL url = new URL(path);
PrintWriter out = null;
HttpURLConnection conn =(HttpURLConnection) url.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(jsonStr);
// flush输出流的缓冲
out.flush();
System.out.println("conn.getResponseCode()=:"+conn.getResponseCode());
StringBuffer msg=new StringBuffer();
// System.out.println("conn.getResponseCode()=:"+conn.getResponseCode());
if (conn.getResponseCode() == 200) {
System.out.println("conn.getResponseCode()=:"+conn.getResponseCode());
BufferedReader in = new BufferedReader(new InputStreamReader(
(InputStream) conn.getInputStream(), "UTF-8"));

        while(in.readLine()!=null){
              msg.append(in.readLine());
        }
        System.out.println("msg=:"+msg);
        in.close();
    }
    conn.disconnect();

    return msg.toString();

}  就是我得到的响应码是415

界面通过form表单提交到Controller Controller得到表单数据存在Map转为json

然后调用远程接口 得到的响应码就是415 这个怎么解决啊?

1个回答

Carry_Dominator
Carry_Dominator   2015.06.07 16:03

HTTP 415 错误 – 不支持的媒体类型。类型不一致导致你的web出现此类状况

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!