我开发了REST服务.我可以通过浏览器或客户端应用程序测试GET方法.但是那些有PUT方法的人我不知道如何通过浏览器来消费它们......
例如,在插入userId之后,我有这个方法打开灯:
@PUT
@Path("/lampon")
@Produces({"application/json", "text/plain"})
@Consumes("multipart/form-data")
public boolean turnOnLamp(@FormParam("userId") String userId) throws Exception
{
boolean response = new LampManager().turnOnLamp(userId);
return response;
}
Run Code Online (Sandbox Code Playgroud)
在我的客户端应用程序中,我这样做,它的工作原理:
String webPage = "http://localhost:8080/BliveServices/webresources/services.actuators/lampon";
URL urlToRequest = new URL(webPage);
//Authentication
urlConnection = (HttpURLConnection) urlToRequest.openConnection();
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestMethod("PUT");
urlConnection.setRequestProperty("Authorization", basicAuth);
urlConnection.setRequestProperty("Content-type", "multipart/form-data");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userId", "2"));
(...)
Run Code Online (Sandbox Code Playgroud)
但是如何通过浏览器发送userId呢?
另一件事,我在构建项目时收到此消息:
SEVERE: Resource methods utilizing @FormParam and consuming "multipart/form-data" are no longer supported. See @FormDataParam.
Run Code Online (Sandbox Code Playgroud)
谢谢
我有以下响应,应该来自MailChimp webhook URL.
这是行BODY:
RAW BODY
type=usub&fired_at=2015-07-23+17%3A19%3A34&data%5Baction%5D=unsub&data%5Breason%5D=manual&data%5Bid%5D=9383uy636&data%5Bemail%5D=youremail%40YOURDOMAIN.com&data%5Bemail_type%5D=html&data%5Bip_opt%5D=202.9.3.003&data%5Bweb_id%5D=404004&data%5Bmerges%5D%5BEMAIL%5D=YOUREMAIL%40YOURDOMAIN.com&data%5Bmerges%5D%5BFNAME%5D=NAME&data%5Bmerges%5D%5BLNAME%5D=LASTNAME&data%5Blist_id%5D=2288883
FORM/POST PARAMETERS
fired_at: 2015-07-22 12:19:34
data[email]: YOUREMAIL@DOMAINNAME.com
data[id]: 56775409ta
data[web_id]: 09833944
data[merges][EMAIL]: YOUREMAIL@DOMAINNAME.com
type: unsub
data[list_id]: 99884hy372
data[merges][FNAME]: Name
data[ip_opt]: 202.0.9.3333
data[reason]: manual
data[email_type]: html
data[action]: unsub
data[merges][LNAME]: LastName
**QUERYSTRING key: a4483983hu473004884j0x**
HEADERS
Accept: */*
Total-Route-Time: 0
Host: requestb.in
Connection: close
Content-Length: 395
User-Agent: MailChimp.com
Connect-Time: 0
Via: 1.1 vegur
X-Request-Id: 6633d8-653e-4cea-884j-9933ju4773h
Content-Type: application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)
我@RequestParameter之前在使用Spring Controllers时曾经使用过,但是我不知道如何从上面的响应中获取数据,例如data [merges] [FNAME]:
我怎样才能在Spring控制器中获取QueryString?QUERYSTRING键:a4483983hu473004884j0x
//I have the following code to …Run Code Online (Sandbox Code Playgroud) 这是我要求卷曲的服务:
time curl -i -XPOST 'http://localhost:9080/my/service' -H "Authorization:OAuth MyToken" -H "Content-Type: application/json" -d "ids=516816b2e4b039526a235e2f,516816b2e4b039526a235e2f"
Run Code Online (Sandbox Code Playgroud)
资源:
@Path("/my")
@Consumes({"application/xml", "application/json"})
@Produces({"application/xml", "application/json", "text/json"})
@Restricted
public class MyResource {
@POST
@Path("/service")
public Map<String ,Object> myService(@FormParam("ids") String myIds) {
// service things
}
}
Run Code Online (Sandbox Code Playgroud)
该服务运行良好,但它突然失败了.现在参数myIds总是为null,而curl的结果是400个错误的请求...我没有更改此资源中的任何内容,因此它应该仍然有效.如果有人有想法,请告诉我.谢谢!
java ×2
http ×1
jax-rs ×1
mailchimp ×1
put ×1
rest ×1
resteasy ×1
spring ×1
spring-mvc ×1
web-services ×1