使用GWT中的参数发出POST请求 [英] Making POST requests with parameters in GWT
本文介绍了使用GWT中的参数发出POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用一组参数对给定的URL执行POST请求。我遇到的问题是发出POST请求,但没有参数传递。
$ b
I am trying to do a POST request with a set of parameters to a given URL. The problem I am having is that the POST request is made, but no parameters are passed.
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
StringBuilder sb = new StringBuilder();
for ( String k: parmsRequest.keySet() ) {
String vx = URL.encodeComponent( parmsRequest.get(k));
if ( sb.length() > 0 ) {
sb.append("&");
}
sb.append(k).append("=").append(vx);
}
try {
Request response = builder.sendRequest( sb.toString(), new RequestCallback() {
public void onError(Request request, Throwable exception) {}
public void onResponseReceived(Request request, Response response) {}
});
} catch (RequestException e) {}
}
如果我使用模式GET并手动将查询字符串添加到请求 - 但我需要使用POST,因为要传递的数据可能很大....
This works just fine if I use mode GET and manually add the querystring to the request - but I need to use POST as the data to be passed along may be large....
推荐答案
设置请求的标题:
Set the header of your request:
builder.setHeader("Content-type", "application/x-www-form-urlencoded");
这篇关于使用GWT中的参数发出POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文