hutool custom request header Request Interface

I. Case column code

Import dependent Maven 1.1

<dependency>
   <groupId>cn.hutool</groupId>
   <artifactId>hutool-all</artifactId>
   <version>4.1.0</version>
</dependency>

 

1.2 preparation of test class (Junit unit testing)

package com.grand.modelSMS;

import org.junit.Test;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;

public class JunitTest {

	@Test
	public void test1() {
		//1. 组建请求json参数
		JSONObject json = new JSONObject();
		json.put("appkey", "2e351b12c5030");
		json.put("androidTitle", "PUSHDEMO");
		Integer[] plat=new Integer[] {1};
		json.put("plats",plat);
		json.put("target", 4);
		String[] registrationId=new String[] {"16772de0f6071dd4024b25de"};
		json.put("registrationIds",registrationId);
		json.put("content","test");
		json.PUT ( "type",. 1); 
		String url=" http://api.push.mob.com/v2/push";
		/ * post send request and receive response data
		 * Uses a chain called programming mode): 
			header corresponding to the request header. 
			the body corresponding to the request body (including parameters and parameter values). 
			HttpRequest which contains Post, GET, Delete, Put other commonly used RestFul way. * / 
		String = HttpRequest.post POST (URL) 
				.header ( "Key", "2e351b12c5030") 
				.header ( "Sign", "ee29e949d8c480a67e61e7921ac2dce7") 
				.body (JSON) 
				. .Execute () body (); 
		the System.out .println (POST); 
	} 

}

  The method of interpretation (using the above chain is called programmatically):
header corresponding to the request header.
the body corresponding to the request body (including parameters and parameter values).
HttpRequest which contains Post, GET, Delete, Put other commonly used RestFul way.

Print 1.3 as follows:

 

 The above code effective pro-test

 

Guess you like

Origin www.cnblogs.com/KdeS/p/12666633.html