【问题标题】:Android HttpPost Returns 500 through Yii FrameworkAndroid HttpPost 通过 Yii 框架返回 500
【发布时间】:2023-03-22 10:30:01
【问题描述】:

我有一个服务器端应用程序,它在Yii Framework 上运行。我想在Android 上使用 Yii 访问数据库(MySQL)。

所以我这样从客户发帖:

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("myurl/reach");

try {
    List<NameValuePair> nmp = new ArrayList<NameValuePair>();
    ResponseHandler<String> responseHandler=new BasicResponseHandler();

    // Parameters are here 
    // nmp.add(new BasicNameValuePair("name", "value"));

    httpPost.setEntity(new UrlEncodedFormEntity(nmp));
    String rs = httpClient.execute(httpPost, responseHandler);
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

这是 Yii 的 urlManager 规则:

'/reach' => 'site/reach',

最后是actionReach()siteController 上的方法:

if(Yii::app()->request->isPostRequest)
{
    // Reach MySQL 
} else
{
    $this->redirect(Yii::app()->homeUrl);   
}

当我尝试运行应用程序时,gettin org.apache.http.client.HttpResponseException: Internal Server Error

这是所有堆栈:

02-22 01:11:18.803: W/System.err(3924): org.apache.http.client.HttpResponseException: Internal Server Error
02-22 01:11:18.823: W/System.err(3924):     at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
02-22 01:11:18.823: W/System.err(3924):     at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
02-22 01:11:18.823: W/System.err(3924):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
02-22 01:11:18.823: W/System.err(3924):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
02-22 01:11:18.828: W/System.err(3924):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
02-22 01:11:18.828: W/System.err(3924):     at com.app.myapp.PostActivity$postInfoTask.doInBackground(PostActivity.java:175)
02-22 01:11:18.828: W/System.err(3924):     at com.app.myapp.PostActivity$postInfoTask.doInBackground(PostActivity.java:1)
02-22 01:11:18.828: W/System.err(3924):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
02-22 01:11:18.833: W/System.err(3924):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-22 01:11:18.833: W/System.err(3924):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-22 01:11:18.833: W/System.err(3924):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
02-22 01:11:18.833: W/System.err(3924):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
02-22 01:11:18.838: W/System.err(3924):     at java.lang.Thread.run(Thread.java:1096)

最后但同样重要的是,当我将 我的网址 reach/ 更改为 reach 时没有错误,但即使我已经发布了 Yii 也会返回主页 html 输出。

我错过了什么?是关于.htaccess 还是什么?

【问题讨论】:

  • 你首先需要在浏览器中尝试你的 yii url 才能看到预期的输出。
  • 并检查服务器上的 php 错误。当我收到错误 500 时,它主要是一些 php 错误
  • 同时检查你的 Yii 路线。 “到达”有什么特别的规则吗?尝试跟踪 apache 日志和 php 错误日志
  • 阿尔芬;我试过了。如果未发布任何内容,应用程序将正确重定向到主页 url。埃里克·霍姆;已经检查过了。规则没问题。 briiC.lv;最后我会检查一下,会发布结果。谢谢大家。

标签: android .htaccess yii http-post


【解决方案1】:

经过长时间的研究,我找到了答案。不幸的是,.htaccess 以某种方式阻止了$_POST。所以我决定将我的动作转移到一个现有的控制器,它已经运行良好

所以,首先将我的路由规则更改为:

'reach/' => 'existed/reach',

在existController中,我写了一个名为reachAction的新动作:

if(Yii::app()->request->isPostRequest)
{
    // MySQL Insert
}

这个 if 语句很好。最后,我从我的模型中得到了一个实例并使用了$model-&gt;save();

就是这样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多