java如何模拟发送form-data的请求
发布时间:2020-07-29 09:14:38
来源:亿速云
阅读:62
作者:小猪
这篇文章主要讲解了java如何模拟发送form-data的请求,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
我就废话不多说了,大家还是直接看代码吧!
package com.silot.test;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
public class TestCli
{
public static void main(String args[]) throws Exception
{
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "------------------------------0ea3fcae38ff", Charset.defaultCharset());
multipartEntity.addPart("skey", new StringBody("哈哈哈哈哈", Charset.forName("UTF-8")));
multipartEntity.addPart("operator", new StringBody("啦啦啦啦", Charset.forName("UTF-8")));
multipartEntity.addPart("VrfKey", new StringBody("渣渣渣", Charset.forName(&