I create a template following django's document:
<h1>{{poll.question}}</h1>
{%if error_message%}<p><strong>{{error_message}}</strong></p>{%endif%}
<form action="/polls/{{poll.id}}/vote" method="post">
{%for choice in poll.get_choice_list%}
<input type="radio" name="choice" id="choice{{forloop.counter}}" value="{{choice.id}}"/>
<label for="choice{{forloop.counter}}">{{choice.choice}}</label><br/>
{%endfor%}
<input type="submit" value="Vote">
</form>
{%if error_message%}<p><strong>{{error_message}}</strong></p>{%endif%}
<form action="/polls/{{poll.id}}/vote" method="post">
{%for choice in poll.get_choice_list%}
<input type="radio" name="choice" id="choice{{forloop.counter}}" value="{{choice.id}}"/>
<label for="choice{{forloop.counter}}">{{choice.choice}}</label><br/>
{%endfor%}
<input type="submit" value="Vote">
</form>
And try to get params from post in python:
def vote(request, poll_id):
p = get_object_or_404(polls, pk=poll_id)
print request.GET
print request.POST
return HttpResponseRedirect('/polls/%s/results/' % p.id)
p = get_object_or_404(polls, pk=poll_id)
print request.GET
print request.POST
return HttpResponseRedirect('/polls/%s/results/' % p.id)
But the result was null:(
{}
{}
While I change the method to get
<form action="/polls/{{poll.id}}/vote" method="get">
I can get the params's value.
{'choice': ['1']}
{}
I don't know why,I wanna help!
相关推荐
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpPost); // 处理响应... ``` 4. **HttpRequest库的使用**: `HttpRequest.rar`...
httpPost.setEntity(new UrlEncodedFormEntity(params)); response = httpClient.execute(httpPost); // 处理响应... ``` 4. **注意点**: - HttpClient的版本选择很重要,不同版本与Java环境的兼容性不同。 ...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; ...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import ...
httpPost.setEntity(new UrlEncodedFormEntity(params)); CloseableHttpResponse response = httpClient.execute(httpPost); try { System.out.println(response.getStatusLine()); ...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; ...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org. apache.http.HttpStatus; import org.apache.http.NameValuePair; ...
import org.apache.http.HttpRequest import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; ...
3. 设置请求体:`httpPost.setEntity(new UrlEncodedFormEntity(params));` 4. 使用HttpClient执行请求:`CloseableHttpResponse response = httpClient.execute(httpPost);` 5. 处理响应,与GET请求相同。 6. 关闭...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; ...
`HttpRequest`可能包含请求方法(GET/POST)、URL、请求头、请求体等信息,而`HttpRevMsg`可能表示HTTP响应,包括状态码、响应头和响应体。这两个类可以提供更高级别的抽象,简化HTTP操作。 总结来说,Java中实现...
Get方法的参数直接附加在URL后面,相比Post方法,它不适用于传输大量或敏感数据。 3. **Android 自制浏览器**: 利用WebView组件,你可以创建一个简单的内置浏览器。在布局文件中添加WebView,如下所示: ```xml...
import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache....
http.send(HttpRequest.HttpMethod.POST, "http://example.com/upload", params, new HttpRequest.OnPostListener() { @Override public void onSuccess(String result) { // 处理结果 } @Override public ...
#### 二、GET与POST方法的区别 在HTTP协议中,GET和POST是最常见的两种请求方式。它们之间的主要区别在于: 1. **传输数据的位置**:GET方法通过URL传递参数,而POST方法将数据放在请求体中发送。 2. **安全性**:...
在使用时,只需实例化`HttpRequest`,调用`get()`或`post()`方法即可发送网络请求。 为了在WiFi和3G之间切换时保持网络连接,我们需要监听网络状态的变化。可以通过注册`BroadcastReceiver`实现: ```java public ...
HttpResponse response = new HttpRequest("http://example.com").post(params); ``` 3. **异步请求处理** JavaLite HTTP库提供了一个回调接口,用于处理异步请求的响应。开发者可以实现`HttpResponseHandler`...
例如,使用HttpURLConnection,你可以创建一个连接,设置请求方法(GET或POST),添加请求头,然后读取响应数据。 2. **Document**: 这里指的是Java DOM解析器,用于解析XML文档。Document对象代表整个XML文档的根...
public static String sendPost(String url, Map, String> params) throws IOException { // 使用HttpClient发送POST请求 } } ``` 以上是一个简单的`HttpRequestUtil`工具类的结构,实际实现需要根据具体需求...