********************************multipart/form-data************************************ public static String apiDemo(String apiUrl, String responseType, String Authorization, String sourceType, String source, String properties, String version,boolean simplify, String capability) { HttpPost post = new HttpPost(apiUrl + "/" + capability); post.addHeader("Authorization", Authorization); post.addHeader("Accept", "application/json"); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("version", new StringBody(version, ContentType.create("multipart/form-data", Charset.forName("UTF-8")))); if (sourceType != null && !sourceType.isEmpty()) { builder.addPart("sourceType", new StringBody(sourceType, ContentType.create("multipart/form-data", Charset.forName("UTF-8"))
HttpClient 三种格式 调用
最新推荐文章于 2024-01-19 09:12:00 发布
本文介绍了使用HttpClient进行API调用的两种常见格式:application/json和application/x-www-form-urlencoded。详细讲解了如何设置请求体及参数,帮助理解两者之间的区别。
摘要由CSDN通过智能技术生成