如何制作HTTPPOST

时间:2016-03-05 16:50:21

标签: android http-post

i want to send parameter in body 我想在身体相同的图片中发送参数

此代码错误:

 StringBuilder str = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        String html = null;
        try {
            httpPost.setHeader("content-type", "application/x-www-form-urlencoded");
            httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
            HttpResponse response1 = client.execute(httpPost);
            StatusLine statusLine = response1.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (statusCode == 200) { // Status OK
                HttpEntity entity = response1.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(content,"UTF-8"));
                String line;
                while ((line = reader.readLine()) != null) {
                    str.append(line);
                }
            } else {
                Log.e("Log", "Failed to download result..");
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str.toString();

堆栈跟踪:

03-06 21:01:10.153 18727-18727 / com.example.tao.navi W / System.err:org.apache.http.conn.HttpHostConnectException:拒绝与http://161.246.37.11的连接 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.HttpConnection.getHttpPostBody(HttpConnection.java:116) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.Login.doSomethingElse(Login.java:114) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.Login.onClick(Login.java:103) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.view.View.performClick(View.java:4756) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.view.View $ PerformClick.run(View.java:19761) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.os.Handler.handleCallback(Handler.java:739) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.os.Handler.dispatchMessage(Handler.java:95) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.os.Looper.loop(Looper.java:135) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at android.app.ActivityThread.main(ActivityThread.java:5253) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at java.lang.reflect.Method.invoke(Native Method) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at java.lang.reflect.Method.invoke(Method.java:372) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:900) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:引起:java.net.ConnectException:无法连接到/161.246.37.11(端口80):连接失败: ENETUNREACH(网络无法访问) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connect(IoBridge.java:124) 03-06 21:01:10.155 18727-18727 / com.example.tao.navi W / System.err:at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at java.net.Socket.connect(Socket.java:882) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:... 19更多 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:引起:android.system.ErrnoException:连接失败:ENETUNREACH(网络无法访问) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.Posix.connect(Native Method) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connectErrno(IoBridge.java:137) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connect(IoBridge.java:122) 03-06 21:01:10.156 18727-18727 / com.example.tao.navi W / System.err:... 24更多 03-06 21:01:10.156 18727-18727 / com.example.tao.navi I / Choreographer:跳过820帧!应用程序可能在其主线程上做了太多工作。 03-06 21:03:40.035 18727-18727 / com.example.tao.navi W / System.err:org.apache.http.conn.HttpHostConnectException:拒绝与http://161.246.37.11的连接 03-06 21:03:40.036 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183) 03-06 21:03:40.036 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 03-06 21:03:40.036 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 03-06 21:03:40.036 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 03-06 21:03:40.036 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.HttpConnection.getHttpPostBody(HttpConnection.java:116) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.Login.doSomethingElse(Login.java:114) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at com.example.tao.navi.Login.onClick(Login.java:103) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.view.View.performClick(View.java:4756) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.view.View $ PerformClick.run(View.java:19761) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.os.Handler.handleCallback(Handler.java:739) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.os.Handler.dispatchMessage(Handler.java:95) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.os.Looper.loop(Looper.java:135) 03-06 21:03:40.037 18727-18727 / com.example.tao.navi W / System.err:at android.app.ActivityThread.main(ActivityThread.java:5253) 03-06 21:03:40.038 18727-18727 / com.example.tao.navi W / System.err:at java.lang.reflect.Method.invoke(Native Method) 03-06 21:03:40.038 18727-18727 / com.example.tao.navi W / System.err:at java.lang.reflect.Method.invoke(Method.java:372) 03-06 21:03:40.038 18727-18727 / com.example.tao.navi W / System.err:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:900) 03-06 21:03:40.038 18727-18727 / com.example.tao.navi W / System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 03-06 21:03:40.038 18727-18727 / com.example.tao.navi W / System.err:引起:java.net.ConnectException:无法连接到/161.246.37.11(端口80):连接失败: ENETUNREACH(网络无法访问) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connect(IoBridge.java:124) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at java.net.Socket.connect(Socket.java:882) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 03-06 21:03:40.040 18727-18727 / com.example.tao.navi W / System.err:at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144) 03-06 21:03:40.041 18727-18727 / com.example.tao.navi W / System.err:... 19更多 03-06 21:03:40.041 18727-18727 / com.example.tao.navi W / System.err:引起:android.system.ErrnoException:连接失败:ENETUNREACH(网络无法访问) 03-06 21:03:40.041 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.Posix.connect(Native Method) 03-06 21:03:40.042 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111) 03-06 21:03:40.042 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connectErrno(IoBridge.java:137) 03-06 21:03:40.042 18727-18727 / com.example.tao.navi W / System.err:at libcore.io.IoBridge.connect(IoBridge.java:122) 03-06 21:03:40.042 18727-18727 / com.example.tao.navi W / System.err:... 24更多

0 个答案:

没有答案