ansetRequestProperty Content-Type和application / json

时间:2016-12-01 09:27:22

标签: android httpurlconnection

我使用像这样的boundaryPostRequest

ORDER BY  CASE WHEN @Ordering = 'asc'  THEN YEAR(TimeIn)           END ASC, 
          CASE WHEN @Ordering = 'asc'  THEN DATEPART(WEEK, TimeIn) END ASC,
          CASE WHEN @Ordering = 'desc' THEN YEAR(TimeIn)           END DESC, 
          CASE WHEN @Ordering = 'desc' THEN DATEPART(WEEK, TimeIn) END DESC  

我想添加内容/类型,json 我试过了:

        final String delimiter = "--";
        con.setRequestMethod(fr.matelli.library.constante.HttpMethod.POST);
        con.setUseCaches(false);
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setRequestProperty("Cache-Control", "no-cache");
        con.setRequestProperty("Connection", "close");
        con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);


        con.setConnectTimeout(60 * 1000);
        con.setReadTimeout(60 * 1000);
        con.connect();
        final OutputStream os = con.getOutputStream();
        os.write((delimiter + boundary + "\r\n").getBytes());
        os.write(("Content-Disposition: form-data; name=\"data\"\r\n").getBytes());
        os.write(("\r\n" + value + "\r\n").getBytes());
        os.write((delimiter + boundary + delimiter + "\r\n").getBytes());


        os.close();

        //con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

但它不起作用我怎么能setRequestProperty Content-Type和application / json?

0 个答案:

没有答案