vertx post与get写法


            vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false)).request(HttpMethod.POST, "45.xxx.127.130", "/gogo", resp -> {
                                                                   ip或域名     域名或ip后的路劲
                resp.bodyHandler(buf -> {
                    JsonObject jsonObject = new JsonObject(buf.toString());
                    System.out.println(jsonObject);
                    System.out.println(jsonObject.getString("msg"));
                });
            }).exceptionHandler(ex -> {
                ex.printStackTrace();
                msg.fail(0, "请求额外失败");
            }).putHeader("Content-Type","application/x-www-form-urlencoded").end("signMethod="+signMethod+"&signature="+signature+"&"+for_post);

POST方式和GET的区别就是把发送的数据和网页地址分离开来。把数据放在HTTP协议的head部分,因此程序中多了一个 设置请求头 ("Content-Type: application/x-www-form-urlencoded") 这个内容你还可以根据你的需要来改变,例如改为图像,或者二进制文件等。

 

一、Form表单语法
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型。 例如: application/x-www-form-urlencoded: 窗体数据被编码为名称/值对。这是标准的编码格式。 multipart/form-data: 窗体数据被编码为一条消息,页上的每个控件对应消息中的一个部分,这个一般文件上传时用。 text/plain: 窗体数据以纯文本形式进行编码,其中不含任何控件或格式字符。
补充

二、常用的编码方式
form的enctype属性为编码方式,常用有两种:application/x-www-form-urlencoded和multipart/form-data,默认为application/x-www-form-urlencoded。

1.x-www-form-urlencoded
当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…),然后把这个字串append到url后面,用?分割,加载这个新的url。

2.multipart/form-data
当action为post时候,浏览器把form数据封装到http body中,然后发送到server。 如果没有type=file的控件,用默认的application/x-www-form-urlencoded就可以了。 但是如果有type=file的话,就要用到multipart/form-data了。浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition(form-data或者file),Content-Type(默认为text/plain),name(控件name)等信息,并加上分割符(boundary)。

 

引用自 : https://blog.csdn.net/qq_28702545/article/details/51719199

 

 

 

-------------------------------------------------------------------------------------------------------------------

 

 

 get写法1

            String for_get = "mchNo=" + mchNo + "&" +
                    "notifyUrl=" + notifyUrl + "&" +
                    "orderCode=" + orderCode + "&" +
                    "price=" + price + "&" +
                    "ts=" + ts + "&" +
                    "type=" + type + "&"+
                    "sign=" + sign;

            vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false)).request(HttpMethod.GET, "www.xxxx.com", "/api/getQrcode?"+for_get, resp -> {
                resp.bodyHandler(buf -> {
                    if (params.getString("payWaySan_jhzf").equals("JHZF_zfb")) {

                        System.out.println(buf.toString());

                        JsonObject json = new JsonObject(buf.toString());

                        msg.reply(json.getString("payUrl"));
                    }
                });
            }).exceptionHandler(ex -> {
                ex.printStackTrace();
                msg.fail(0, "请求额外失败");
            }).end();

 get写法2

            String for_get = "p00_spid="+p00_spid+"&"+
                    "p01_paytype="+p01_paytype+"&"+
                    "p02_spbillno="+p02_spbillno+"&"+
                    "p03_money="+p03_money+"&"+
                    "p04_callbackurl="+p04_callbackurl+"&"+
                    "p05_returnurl="+p05_returnurl+"&"+
                    "p07_productname="+p07_productname+"&"+
                    "pn_sign="+sign;

            System.out.println(for_get);

            vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false)).request(HttpMethod.GET,2188,"47.52.209.6", "/tongda/v6/pay", resp -> {
                resp.bodyHandler(buf -> {
                    System.out.println(resp.statusCode());
                    System.out.println("返回 ===== :"+buf.toString());

//                    JsonObject json = new JsonObject(buf.toString());
//
//                    if(json.getInteger("status") == 200){
//                        System.out.println(new JsonObject(buf.toString()).toString());
//                        msg.reply(json.getString("payUrl"));
//                    }else {
//                        msg.fail(0, "失败");
//                    }

                });
            }).exceptionHandler(ex -> {
                ex.printStackTrace();
                msg.fail(0, "请求TongDa失败");
            }).putHeader("Content-Type","application/x-www-form-urlencoded").end(for_get);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM