OkHttp Post提交json数据

new Thread() {
            @Override
            public void run() {
                // @Headers({"Content-Type:application/json","Accept: application/json"})//需要添加头
                MediaType JSON = MediaType.parse("application/json;charset=utf-8");
                JSONObject json = new JSONObject();
                try {
                    json.put("EngineerId", getString(ShareFile.UID, ""));
                    json.put("EngorderNumber", orderNumber);
                    json.put("PID", pid);
                    json.put("RefundType", RefundType);
                    json.put("RefundReason", reason_text.getText().toString());
                    json.put("RefundImg", str);
                    json.put("RefundVideo", "");
                    json.put("discount", discount);
                    json.put("RefundState", "0");
                    json.put("shopkeeperId", shopkeeperId);
                    json.put("payMoney", ActualPayment);//tuikuanPriceString
                    json.put("refundNum", number);
                    json.put("RefundCategory", RefundCategory);
                    json.put("sidd", oldsidd + "");
                    if (RefundCategory.equals("2")) {
                        json.put("ExchangePID", pid);
                        json.put("ExchangeSidd", sidd + "");
                    } else {
                        json.put("ExchangePID", "");
                        json.put("ExchangeSidd", "");
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                //申明给服务端传递一个json串
                //创建一个OkHttpClient对象
                OkHttpClient okHttpClient = new OkHttpClient();
                //创建一个RequestBody(参数1:数据类型 参数2传递的json串)
                //json为String类型的json数据
                RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
                //创建一个请求对象
//                        String format = String.format(KeyPath.Path.head + KeyPath.Path.waybillinfosensor, username, key, current_timestamp);
                Request request = new Request.Builder()
                        .url(NetUtil.saveEngRefundInfo())
                        .post(requestBody)
                        .build();

                okHttpClient.newCall(request).enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        //DialogUtils.showPopMsgInHandleThread(Release_Fragment.this.getContext(), mHandler, "数据获取失败,请重新尝试!");
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        String string = response.body().string();
                        Log.i("info",string+"");
                        try {
                            JSONObject json = new JSONObject(string);
                            strddd = json.optString("msg");
                            handler.sendEmptyMessage(0x11);
                            if (json.optString("flag").equals("00")) {
                                finish();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        }.start();
  • 7
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值