没有参数名称的Android HttpPost

时间:2014-01-22 16:46:02

标签: android http-post

Image to post request using

我过去曾多次使用过POST方法,但却得到了这种奇怪的Web服务。它在chrome扩展程序上工作正常,但我无法使用android获得此响应。如果缺少

,请在代码中添加任何内容

这是我正在使用的代码

              HttpParams param = new BasicHttpParams();
            param.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            HttpClient httpclient = new DefaultHttpClient(param);
            HttpPost httppost = new HttpPost(url);
            Utils.showLogs(MyConstants.TAG, "ApplicationURL: " + url);

            httppost.setHeader("Content-type", contentType);
            HttpConnectionParams.setConnectionTimeout(param, MyConstants.WEBSERVICE_TIMEOUT);
            HttpConnectionParams.setSoTimeout(param, MyConstants.WEBSERVICE_TIMEOUT);

            String response = null;
            try {
                if (jsonObject == null) {
                    StringEntity entity = new StringEntity(json, HTTP.UTF_8);
                    httppost.setEntity(entity);
                } else {
                    StringEntity stringEntity = new StringEntity(jsonObject.toString());
                    httppost.setEntity(stringEntity);

                }
                // Execute HTTP Post Request
                HttpResponse httpResponse = httpclient.execute(httppost);
                final int statusCode = httpResponse.getStatusLine().getStatusCode();
                if (statusCode != HttpStatus.SC_OK) {
                    return MyConstants.SERVER_NOT_RESPONDING;
                }
                HttpEntity httpEntity = httpResponse.getEntity();
                response = EntityUtils.toString(httpEntity);

由于

1 个答案:

答案 0 :(得分:0)

您是否在<uses-permission android:name="android.permission.INTERNET" />中添加了AndroidManifest.xml

如果没有,加上这个应该没问题!