2 z303000325 z303000325 于 2013.12.31 11:08 提问

用 httpclient 上传文件 和 普通参数 时服务器返回400
public void run() {
    //TelephonyManager telephonyManager= (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    try {
        HttpClient clicent = new DefaultHttpClient();
        HttpPost post = new HttpPost(actionUrl);
        //FileBody fileBody = new FileBody(files.get("img"));
        //用这里的代码服务器返回400错误
        //MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
        //entity.addPart("cId",new StringBody("11",Charset.forName(HTTP.UTF_8)));
        //entity.addPart("img",new FileBody(files.get("img")));

        List<NameValuePair> params= new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("cId","111"));
        post.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));

        //post.setEntity(entity);
        HttpResponse httpResponse = clicent.execute(post);
        if (httpResponse.getStatusLine().getStatusCode()==200) {
            System.out.println(httpResponse.getStatusLine().getStatusCode());
        }
        System.out.println(httpResponse.getStatusLine().getStatusCode());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!