• java post json sample


    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class Test {
    
        public static void main(String[] args) {
            try {
                URL url = new URL("http://192.168.0.xx:81/OMS/Service/Mobile/MarkingService.svc/Question");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("POST");
                conn.setDoOutput(true);
                conn.setDoInput(true);
                conn.setRequestProperty("mobiletoken", "EFF881DDCDC1FA833F3EF79EE414AC3250CA843E6B5027B516BD33F791D62E6E8DEDD421DB5EB109DCBFCB38817EEA45526D004C739DC1D75E098F65C0A8EBDFB64774E456C0F75F8A4DD6391D8AFFD497F66C2E5D508E8ECC28EE8637FC0EE69D80DF87B8A8F16474925E8217C48C6BEAEB39578C6E765259754237472CB51DBACFFB9603A8FE590642E2480531A734954424EA17B350AF8EE1B0E1523A27B97148CAD0018BC0000A175A5C3278C4D0D10F4C1106AB44B0EBF1109CDAE5057F");
                conn.setRequestProperty("Content-Type","application/json; charset=UTF-8");
    
                String Json = "{"MarkingMode":2,"QuestionGroupCode":"61010100011701021601000301","ScoreList":[{"MajorQuestionID":13,"MinorQuestionID":0,"Score":2,"StudentCode":"103080802011"}]}";
                byte[] writebytes = Json.getBytes();
                conn.setRequestProperty("Content-Length", String.valueOf(writebytes.length));
                OutputStream outwritestream = conn.getOutputStream();
                outwritestream.write(Json.getBytes());
                outwritestream.flush();
                outwritestream.close();
    
                if (conn.getResponseCode() == 200) {
                    System.out.println("ok!");
                }
                    
            } catch (java.net.SocketTimeoutException e) {
               System.out.println("Request Timeout!");
            } catch (java.io.IOException e) {
                System.out.println("Request Error:" + e.getMessage());
            }
            
            System.out.println("End!");
        }
    
    }
  • 相关阅读:
    js代码编写规范
    mysql数据库的水平拆分与垂直拆分
    git使用WebHook实现自动构建
    解决php
    laravel为模型中所有查询统一添加WHERE条件
    centos7+ 安装 php7.2
    nginx配置https
    git常用命令
    php如何应对秒杀抢购高并发思路
    nginx配置优化+负载均衡+动静分离详解
  • 原文地址:https://www.cnblogs.com/nanfei/p/8317519.html
Copyright © 2020-2023  润新知