Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用程序在使用多端口执行http post时崩溃_Android_Multipartentity - Fatal编程技术网

Android应用程序在使用多端口执行http post时崩溃

Android应用程序在使用多端口执行http post时崩溃,android,multipartentity,Android,Multipartentity,我正在尝试使用android HttpPost向服务器发布带有用户名、用户id和个人资料图片的数据。当我执行http post时,应用程序崩溃,日志中没有显示任何内容。我的代码如下: protected String doInBackground(String... params) { if(params==null || params.length <= 0) return null; try { String apiUrl = "";

我正在尝试使用android HttpPost向服务器发布带有用户名、用户id和个人资料图片的数据。当我执行http post时,应用程序崩溃,日志中没有显示任何内容。我的代码如下:

protected String doInBackground(String... params) {
    if(params==null || params.length <= 0) return null;

    try {
        String apiUrl = "";


        File file = new File(params[2]);
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("name", new StringBody(params[0]));
        entity.addPart("userID", new StringBody(params[1]));
        entity.addPart("userfile", new FileBody(file));

        apiUrl = "/api/consumer/" +  Globals.USER_ID + "/profile/edit";
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(
                Globals.BASE_URL + apiUrl);

        httpPost.setEntity(entity);
        HttpResponse resp = httpClient.execute(httpPost); //crash here..
        String respStr = EntityUtils.toString(resp.getEntity());
        return respStr;

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
受保护的字符串doInBackground(字符串…参数){

如果(params==null | | params.length,请检查您的logcat是否存在异常。在捕获异常的地方,请使用Log.e()打印异常,而不是忽略它们。只需调试它并在每个捕获块中添加调试指针。然后您就可以找到异常消息。