Android http post提供非法状态异常

Android http post提供非法状态异常,android,http-post,httpresponse,Android,Http Post,Httpresponse,这是我用于HTTP post的代码 public void postData() { //DineOutActivity doa = null; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("192.168.1.112/andro/index.php/androctrl/test/"); try { //food item

这是我用于HTTP post的代码

public void postData() {

    //DineOutActivity doa = null;
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("192.168.1.112/andro/index.php/androctrl/test/");

    try {

        //food item
     Spinner spinner = (Spinner) findViewById(R.id.spinner1);
     String fooditem = spinner.getSelectedItem().toString();

     TextView mDateDisplay = (TextView)findViewById(R.id.textView2);
     String Date = mDateDisplay.toString();

     TextView mTimeDisplay  = (TextView)findViewById(R.id.textView4);
     String Time = mTimeDisplay.toString();



        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("fooditem", "fooditem"));
        nameValuePairs.add(new BasicNameValuePair("Date", "Date"));
        nameValuePairs.add(new BasicNameValuePair("Time", "Time"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        String str = inputStreamToString(response.getEntity().getContent()).toString();
        Log.w("ADPORTAL", str);
        HttpStatus status;

        if(str.toString().equalsIgnoreCase("false"))
        {Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
            //result.setText("You are not registerd please register"
        }
        else
        {Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();}



    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
} 

private StringBuilder inputStreamToString(InputStream is) {
    String line = "";
    StringBuilder total = new StringBuilder();
    // Wrap a BufferedReader around the InputStream
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    // Read response until the end
    try {
        while ((line = rd.readLine()) != null) { 
            total.append(line); 
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Return full string
    return total;
我在
postData
方法中有一个
异常
一致

HttpResponse response = httpclient.execute(httppost);
logcat的例外情况是:

05-04 11:53:00.096: E/AndroidRuntime(4281): FATAL EXCEPTION: main
05-04 11:53:00.096: E/AndroidRuntime(4281): java.lang.IllegalStateException: Could not execute method of the activity
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.view.View$1.onClick(View.java:2144)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.view.View.performClick(View.java:2485)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.view.View$PerformClick.run(View.java:9080)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.os.Handler.handleCallback(Handler.java:587)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.os.Looper.loop(Looper.java:130)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.app.ActivityThread.main(ActivityThread.java:3687)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at java.lang.reflect.Method.invokeNative(Native Method)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at java.lang.reflect.Method.invoke(Method.java:507)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at dalvik.system.NativeStart.main(Native Method)
05-04 11:53:00.096: E/AndroidRuntime(4281): Caused by: java.lang.reflect.InvocationTargetException
05-04 11:53:00.096: E/AndroidRuntime(4281):     at java.lang.reflect.Method.invokeNative(Native Method)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at java.lang.reflect.Method.invoke(Method.java:507)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at android.view.View$1.onClick(View.java:2139)
05-04 11:53:00.096: E/AndroidRuntime(4281):     ... 11 more
05-04 11:53:00.096: E/AndroidRuntime(4281): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters.
05-04 11:53:00.096: E/AndroidRuntime(4281):     at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:577)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at com.crews.dineout.DineOutActivity.postData(DineOutActivity.java:243)
05-04 11:53:00.096: E/AndroidRuntime(4281):     at com.crews.dineout.DineOutActivity.imageclick(DineOutActivity.java:209)
05-04 11:53:00.096: E/AndroidRuntime(4281):     ... 14 more
我使用手机跑步,手机有wifi连接
我有互联网许可。

看起来你的URI无效。-

您缺少该方案-http

HttpPost httppost = new HttpPost("http://192.168.1.112/andro/index.php/androctrl/test/")

请不要大写你的标题“HTTP POST给予非法状态异常”这是不必要的。好吧,我会编辑它,我正在根据你的回答进行尝试。我正在与服务器端进行检查,到那时在添加名称值之前是否有任何错误/映射。pairI尝试了你所说的,但数据正在作为“fooditem”插入,0000-00-00,00:00我的意思是,我无法获得插入的准确数据。检查此项确定,我将回答新问题。如果答复帮助您非法登录,请考虑将其标记为“为所有人受益”。
HttpPost httppost = new HttpPost("http://192.168.1.112/andro/index.php/androctrl/test/")