android post資料/問題

來源:互聯網
上載者:User

我快被整瘋了,對網路知識的不懂導致開發基於伺服器的用戶端很費勁,今天出現了一個問題就讓我很無奈,伺服器端是用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 blocke1.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 blocke.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.com07-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最後邊沒有/的原因嗎? 我把/加上就好了,我就服了,這些知識在哪學?求大神指導~~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.