我是springboot的新手,我想问问如何实现将数据发送到指定url的参数
http://api.gosmsgateway.net/masking/api/Send.php?username=ecgo&mobile=082111937220&message=7521&password=123456
答案 0 :(得分:1)
我认为您错了,因为该URL类似于GET方法,但是如果您愿意,我将向您展示如何发送POST请求。
在春季,您可以使用Rest Template进行请求。
Here is也是Spring提供的使用方法的正式示例。
因此,在您的情况下,您必须使用该参数将请求发送到网址http://api.gosmsgateway.net/masking/api/Send.php
:
username=ecgo&mobile=082111937220&message=7521&password=123456
基于this method.
String url = "http://api.gosmsgateway.net/masking/api/Send.php";
Map<String, String> params = new HashMap<>(); // put here your params.
RestTemplate template = new RestTemplate();
template.postForLocation(url, postObject, params);
但是我认为您不应该在url中发送参数,因为这确实是一种不好的做法。