app为什么发送简单的json语句服务器收不到?

村西埋个地雷 发布于 2016/09/27 15:29
阅读 150
收藏 0
try { JSONObject userJSON = new JSONObject(); userJSON.put("userName",m.getSn()); userJSON.put("userPassword",m.getPassword()); //*JSONObject test = new JSONObject(); String a = userJSON.getString("userName"); String b = userJSON.getString("userPassword"); System.out.println(a+"用户名打印"); System.out.println(b+"密码打印"); //把JSON数据转换成String类型使用输出流向服务器写 String content = String.valueOf(userJSON); System.out.println("json格式的字符串"+content); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(5000); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("User-Agent", "Fiddler"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Charset", "UTF-8"); connection.connect(); OutputStream os = connection.getOutputStream(); os.write(content.getBytes()); os.flush(); os.close(); }
加载中
返回顶部
顶部