Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Custom parameter length when HttpClient does interface test

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

When doing http interface testing, you always have to do a lot of parameters and values, and the whole interface looks quite awkward, so you put the combination of parameters into one method and the execution into one method, and the main function just needs to get the response string to do processing and make assertions, so this code looks much cleaner, and the jar packages of httpclient, dom4j and testng are used here.

Import java.io.IOException

Import java.io.UnsupportedEncodingException

Import java.util.ArrayList

Import java.util.List

Import org.apache.http.HttpEntity

Import org.apache.http.NameValuePair

Import org.apache.http.client.ClientProtocolException

Import org.apache.http.client.entity.UrlEncodedFormEntity

Import org.apache.http.client.methods.CloseableHttpResponse

Import org.apache.http.client.methods.HttpPost

Import org.apache.http.impl.client.CloseableHttpClient

Import org.apache.http.impl.client.HttpClients

Import org.apache.http.message.BasicNameValuePair

Import org.apache.http.util.EntityUtils

Import org.dom4j.Document

Import org.dom4j.DocumentException

Import org.dom4j.DocumentHelper

Import org.dom4j.Element

Import org.testng.AssertJUnit

Public class HttpInterfaceTest {

Private static String url

Private static String [] [] keyVlaueList = {{"cdkey", "6SDK"}, {"password", "160489"}}; / / customize the number and values of API parameters as needed

Private static List postPara = new ArrayList ()

Private static String responseEntiy

/ * *

* Assembly request parameters

* @ param keyVlaueList

, /

Public static List getPostPara (String [] keyVlaueList) throws DocumentException {

For (int I = 0 position I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report