dongpengyu1363 2014-12-30 07:29
浏览 19

基于Laravel的网站的Android登录无法正常工作(HttpPost方法无法正常工作)

This could be pretty much a beginners question but I am struggling to find a solution here.

I have my Laravel based website live and I am trying to design an android application for the same. Using the normal android login functionality (added the code below) I am sending an http post request to my server, however, I get the following error:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Controller method not found.

Now,according to my knowledge I am getting this error because the request somehow is converted to http get request and hence the path is not found. Please find a small snapshot of my code below:

protected String doInBackground(Void... params) {
            InputStream is = null;
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost request = new HttpPost("http://my.server.address/users/signin/");
                List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("email", "someuser"));
                postParameters.add(new BasicNameValuePair("password", "somedata"));
                UrlEncodedFormEntity form = new UrlEncodedFormEntity(postParameters);
                request.setEntity(form);
                HttpResponse response = httpclient.execute(request);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
            } catch (Exception e) {
                Log.e("log_tag", "Error in http connection " + e.toString());
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        is, "iso-8859-1"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "
");
                }
                is.close();
                setResult(sb.toString());
                //System.out.println(sb.toString());
                //     this.jArray = new JSONArray(result);
            } catch (Exception e) {
                Log.e("log_tag", "Error converting result " + e.toString());
            }
            return getResult();
        }

Edit 1: getSigin Mehtod works (so definitely, the post requests are converted to get)

So, well, I created a getSignin method to check whether my guess was true, and yes, that was the problem, the server somehow interprets the request as GET instead of POST.

Any help here would really appreciated, I have wasted hours on this. Also, please correct me if the approach is wrong.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本