Practical use of doPost

Table of contents

Preface

1. What is doPost?

2. Usage steps

1.doPost request method

2. Need to introduce dependencies

Summarize


Preface

This chapter mainly records the use of doPost's request public methods.

1. What is doPost?

It is actually an http post request method.

2. Usage steps

1.doPost request method

When our system calls the interface of another system, we can use the post request method to request. Then we need a public method to send http requests. The params in the picture is a HashMap, which is mainly used to store Parameters, when you need to send parameters to another system. And TextUtils.format, it is a tool for assembling URLs.

public void doPost(SalesInvoicingssCallsbackBean bean,String srcsPlatsform,String systerUrl,String host){
        Map<String, Object> params = Maps.newHashMap();
        params.put("srcPlatssform",srcPlatform); 
        params.put("requestssSerialNo", bean.getQqlshYwxt()); 
        params.put("invoicessCode", bean.getFpDm());  
        params.put("invoicessNumber", bean.getFpHm()); 
        params.put("pdfDownssloadUrl", bean.getPdfUrl()); 
        params.put("statusssType", bean.getRequestStatusType());
        logger.info("参数是"+params);
        String url = TextUtils.format(systerUrl, host);
        DataResult<String> returnResult;
        try {
            String json = restRequester.post(url, params);
            returnResult = Jack.toObjByReference(json, new TypeReference<DataResult<String>>() {
            });
            if(returnResult.getStatus()==0){
                // TODO 4.发送成功后,回写ProcStatus,作为请求成功。
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnssResult = DataResults.fail(-1, e.getMessage());

        }
    }

The code is as follows (example):

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import  ssl
ssl._create_default_https_context = ssl._create_unverified_context

2. Need to introduce dependencies

From the restRequester.post method in Figure 1, you can initiate an http request to another system. It is recommended to use the 443 port request method of https because it is encrypted and is not easy to leak data, rather than using the 80 port request method of http. , because it is in clear text, data is easily leaked.

 The corresponding maven requires the introduction of the corresponding jar package or remote jar package.

The code is as follows (example):

data = pd.read_csv(
    'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())

The data requested by the url network used here.


Summarize

This chapter mainly records the use of doPost's request public methods.

Guess you like

Origin blog.csdn.net/weixin_46442877/article/details/129397111