我快被整疯了,对网络知识的不懂导致开发基于服务器的客户端很费劲,今天出现了一个问题就让我很无奈,服务器端是用django写的,由于本人对django也是个菜鸟,领导让用也木有办法,django中写了一个测试页面,如果是用get方式访问的,返回一个值,如果是post则返回另一个值。
if request.method == 'POST':
return HttpResponse("Success")
else:
return HttpResponse("Error")
我写了一个html用来post数据,木有任何问题
<html>
<form name="input" action="http://12.23.4.5/reigster/" {% csrf_token %} method="post">
Username:
<input type="submit" value="Submit" />
</form>
<html>
使用android进行post的时候每次返回的结果都是一大堆,服务器显示500异常
private String url = "http://12.23.4.5/reigster";
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
HttpGet request = new HttpGet(url);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year", "1980"));
try {
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
StringEntity s = null;
try {
s = new StringEntity("test", HTTP.UTF_8);
s.setContentType("text/xml charset=utf-8");
post.setEntity(s);
HttpResponse re=httpclient.execute(post);
//HttpResponse re=httpclient.execute(request);
String result = EntityUtils.toString(re.getEntity(), null);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch ( ClientProtocolException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
返回的结果是:
07-25 07:05:04.812: I/xiao(501): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
07-25 07:05:04.812: I/xiao(501): <html lang="en">
07-25 07:05:04.812: I/xiao(501): <head>
07-25 07:05:04.812: I/xiao(501): <meta http-equiv="content-type" content="text/html; charset=utf-8">
07-25 07:05:04.812: I/xiao(501): <meta name="robots" content="NONE,NOARCHIVE">
07-25 07:05:04.812: I/xiao(501): <title>RuntimeError at /register_personal</title>
07-25 07:05:04.812: I/xiao(501): <style type="text/css">
07-25 07:05:04.812: I/xiao(501): html * { padding:0; margin:0; }
07-25 07:05:04.812: I/xiao(501): body * { padding:10px 20px; }
07-25 07:05:04.812: I/xiao(501): body * * { padding:0; }
07-25 07:05:04.812: I/xiao(501): body { font:small sans-serif; }
07-25 07:05:04.812: I/xiao(501): body>div { border-bottom:1px solid #ddd; }
07-25 07:05:04.812: I/xiao(501): h1 { font-weight:normal; }
07-25 07:05:04.812: I/xiao(501): h2 { margin-bottom:.8em; }
07-25 07:05:04.812: I/xiao(501): h2 span { font-size:80%; color:#666; font-weight:normal; }
07-25 07:05:04.812: I/xiao(501): h3 { margin:1em 0 .5em 0; }
07-25 07:05:04.812: I/xiao(501): h4 { margin:0 0 .5em 0; font-weight: normal; }
07-25 07:05:04.812: I/xiao(501): code, pre { font-size: 100%; }
07-25 07:05:04.812: I/xiao(501): table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
07-25 07:05:04.812: I/xiao(501): tbody td, tbody th { vertical-align:top; padding:2px 3px; }
07-25 07:05:04.812: I/xiao(501): thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; }
07-25 07:05:04.812: I/xiao(501): tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
07-25 07:05:04.812: I/xiao(501): table.vars { margin:5px 0 2px 40px; }
07-25 07:05:04.812: I/xiao(501): table.vars td, table.req td { font-family:monospace; }
07-25 07:05:04.812: I/xiao(501): table td.code { width:100%; }
07-25 07:05:04.812: I/xiao(501): table td.code pre { overflow:hidden; }
07-25 07:05:04.812: I/xiao(501): table.source th { color:#666; }
07-25 07:05:04.812: I/xiao(501): table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
07-25 07:05:04.812: I/xiao(501): ul.traceback { list-style-type:none; }
07-25 07:05:04.812: I/xiao(501): ul.traceback li.frame { padding-bottom:1em; }
07-25 07:05:04.812: I/xiao(501): div.context { padding:10px 0; overflow:hidden; }
07-25 07:05:04.812: I/xiao(501): div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
07-25 07:05:04.812: I/xiao(501): div.context ol li { font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
07-25 07:05:04.812: I/xiao(501): div.context ol li pre { display:inline; }
07-25 07:05:04.812: I/xiao(501): div.context ol.context-line li { color:black; background-color:#ccc; }
07-25 07:05:04.812: I/xiao(501): div.context ol.context-line li span { position:absolute; right:32px; }
07-25 07:05:04.812: I/xiao(501): div.commands { margin-left: 40px; }
07-25 07:05:04.812: I/xiao(501): div.commands a { color:black; text-decoration:none; }
07-25 07:05:04.812: I/xiao(501): #summary { background: #ffc; }
07-25 07:05:04.812: I/xiao(501): #summary h2 { font-weight: normal; color: #666; }
07-25 07:05:04.812: I/xiao(501): #explanation { background:#eee; }
07-25 07:05:04.812: I/xiao(501): #template, #template-not-exist { background:#f6f6f6; }
07-25 07:05:04.812: I/xiao(501): #template-not-exist ul { margin: 0 0 0 20px; }
07-25 07:05:04.812: I/xiao(501): #unicode-hint { background:#eee; }
07-25 07:05:04.812: I/xiao(501): #traceback { background:#eee; }
07-25 07:05:04.812: I/xiao(501): #requestinfo { background:#f6f6f6; padding-left:120px; }
07-25 07:05:04.812: I/xiao(501): #summary table { border:none; background:transparent; }
07-25 07:05:04.812: I/xiao(501): #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
07-25 07:05:04.812: I/xiao(501): #requestinfo h3 { margin-bottom:-1em; }
07-25 07:05:04.812: I/xiao(501): .error { background: #ffc; }
07-25 07:05:04.812: I/xiao(501): .specific { color:#cc3300; font-weight:bold; }
07-25 07:05:04.812: I/xiao(501): h2 span.commands { font-size:.7em;}
07-25 07:05:04.812: I/xiao(501): span.commands a:link {color:#5E5694;}
07-25 07:05:04.812: I/xiao(501): pre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }
07-25 07:05:04.812: I/xiao(501): </style>
07-25 07:05:04.812: I/xiao(501):
07-25 07:05:04.812: I/xiao(501): <script type="text/javascript">
07-25 07:05:04.812: I/xiao(501): //<!--
07-25 07:05:04.812: I/xiao(501): function getElementsByClassName(oElm, strTagName, strClassName){
07-25 07:05:04.812: I/xiao(501): // Written by Jonathan Snook, http://www.snook.ca/jon; Add-ons by Robert Nyman, http://www.robertnyman.com
07-25 07:05:04.812: I/xiao(501): var arrElements = (strTagName == "*" && document.all)? document.all :
07-25 07:05:04.812: I/xiao(501): oElm.getElementsByTagName(strTagName);
07-25 07:05:04.812: I/xiao(501): var arrReturnElements = new Array();
07-25 07:05:04.812: I/xiao(501): strClassName = strClassName.replace(/\-/g, "\-");
07-25 07:05:04.812: I/xiao(501): var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
07-25 07:05:04.812: I/xiao(501): var oElement;
07-25 07:05:04.812: I/xiao(501): for(var i=0; i<arrElements.length; i++){
07-25 07:05:04.812: I/xiao(501): oElement = arrElements[i];
07-25 07:05:04.812: I/xiao(501): if(oRegExp.test(oElement.className)){
07-25 07:05:04.812: I/xiao(501): arrReturnElements.push(oElement);
07-25 07:05:04.812: I/xiao(501): }
07-25 07:05:04.812: I/xiao(501): }
07-25 07:05:04.812: I/xiao(501): return (arrReturnElements)
07-25 07:05:04.812: I/xiao(501): }
07-25 07:05:04.812: I/xiao(501): function hideAll(elems) {
07-25 07:05:04.812: I/xiao(501): for (var e = 0; e < elems.length; e++) {
07-25 07:05:04.812: I/xiao(501): elems[e].style.display = 'none';
07-25 07:05:04.812: I/xiao(501): }
07-25 07:05:04.812: I/xiao(501): }
07-25 07:05:04.812: I/xiao(501): window.onload = function() {
07-25 07:05:04.812: I/xiao(501): hideAll(getElementsByClassName(document, 'table', 'vars'));
07-25 07:05:04.812: I/xiao(501): hideAll(getElementsByClassName(document, 'ol', 'pre-context'));
07-25 07:05:04.812: I/xiao(501): hideAll(getElementsByClassName(document, 'ol', 'post-conte
搞了很久才想起来难道是因为url最后边没有/的原因吗? 我把/加上就好了,我就服了,这些知识在哪学?求大神指导~~