SpringBoot请求第三方接口[通俗易懂]

SpringBoot请求第三方接口[通俗易懂]/*SpringBoot请求第三方接口*/Stringurl=”http://192.168.3.8:8011/file/openadd”;RestTemplateclient=newRestTemplate();//设置请求头HttpHeadersheaders=newHttpHeaders();MediaTypetype=MediaType.pa…

大家好,又见面了,我是你们的朋友全栈君。


/* SpringBoot请求第三方接口  */
String url="http://192.168.3.8:8011/file/openadd";
RestTemplate client = new RestTemplate();

// 设置请求头
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("multipart/form-data");
headers.setContentType(type);

// 设置请求体,注意是LinkedMultiValueMap
FileSystemResource fileSystemResource = new FileSystemResource(uploadedFile);
MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();

UUIDFileName = UUID.randomUUID().toString().replace("-","");
form.add("file", fileSystemResource);
form.add("fileName",UUIDFileName);
form.add("type",3);
form.add("updateFlag",0);
form.add("createByName",""+ UserUtils.getUser().getName());
form.add("createBy",""+UserUtils.getUser().getId());

// 用HttpEntity封装整个请求报文
HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(form, headers);

String str = client.postForObject(url, files, String.class);


 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/135209.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android 代码混淆 选项说明[通俗易懂]

    Android 代码混淆 选项说明[通俗易懂]转载请注明出处:Android代码混淆选项说明http://blog.csdn.net/jjwwmlp456/article/details/44977721—————–匆忙拥挤repeat语法规范说明地址:https://stuff.mit.edu/afs/sipb/project/android/sdk/android-…

    2022年5月29日
    63
  • C++ filesystem

    C++ filesystem命名空间:std::tr2::sys头文件:#include1.路径或文件是否存在templateinlineboolexists(constPath&Pval);std::tr2::sys::pathmyfile(R”(D:\胡军军\TestStatu.xm)”); if(std::tr2::sys::exists(myfile)){  

    2025年6月8日
    2
  • fopen函数打开文件失败原因_为什么打开文件失败

    fopen函数打开文件失败原因_为什么打开文件失败大家好,我是疯狂的比特,一个每天在互联网上种菜和砍柴的程序员今天给大家分享一个C语言初学者常见的一个问题。问题经常有人问我,我的C语言代码好好的,怎么就打开文件失败了呢?我们先来看看代码吧#include<stdio.h>#include<stdlib.h>intmain(){ FILE*pfRead=fopen(“test.txt”,”r”); if(pfRead==NULL) { printf(“打开文件test.txt失败啦\

    2022年10月14日
    2
  • 手把手教你在Linux环境下安装Python3「建议收藏」

    在上一篇文章《手把手教你启用Win10的Linux子系统(超详细)》我们已经学了如何在Win10环境下装Linux子系统了,那么这一篇文章我们将学习如何在该Linux系统下安装Python3。首先是按Win+R键调出cmd命令窗口,然后输入输入bash指令进入Ubuntu系统,接着就可以进入正式的安装过程了。第一步、下载Python3输入下载命令:wgethttps://w…

    2022年4月17日
    39
  • int是什么_int a[4][4]

    int是什么_int a[4][4]Int16意思是16位整数(16bitinteger),相当于short占2个字节-32768~32767Int32意思是32位整数(32bitinteger),相当于int占4个字节-2147483648~2147483647Int64意思是64位整数(64bitinterger),相当于longlong占8个字节…

    2022年8月15日
    6
  • ubuntu分区方案(合并分区)

    MostPCoperatingsystemsstillworkwithanancientdiskpartitionschemethathistoricallymakesdistinctionbetweenprimaryandextendedpartitions.Italsoplacesalimitationforfourprimarypart

    2022年4月14日
    527

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号