android中的“无效参数”错误

时间:2013-12-27 14:18:19

标签: android error-handling http-post

我正在尝试在Php服务器上传文件。服务器接受包含Userid,密码和视频文件的请求。

以下是服务器端代码。

public function uploadVideoAction(Request $request) {
  $tranlator = $this->get('translator');
  $sUserName = $request->request->get('username');
  $passWord  = $request->request->get('password');
  if(empty($sUserName) || empty($passWord) || empty($_FILES['video_profile_candidate'])) {
            $view = View::create()
                    ->setStatusCode(400)
                    ->setData(array(
                        'message' => $tranlator->trans('Invalid parameters')
                    ));
            return $this->get('fos_rest.view_handler')->handle($view);
  }

当我试图通过HttpPost从android发送请求时出现“无效参数”错误。任何人都可以帮助我。

这是我的安卓代码

JSONObject jsonObject = new JSONObject();
        try
             {
              jsonObject.put(CommonString.LOGIN_USER_NAME,"username");
              jsonObject.put(CommonString.LOGIN_PASSWORD,"####");
              System.out.println("object "+jsonObject);
    }
             catch (JSONException e)
    {
     e.printStackTrace();
    }

     HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpost = new HttpPost("url");
        Log.i(TAG, "request :url");
        httpost.setHeader("Content-type", "application/x-www-urlendcode");       
        File file = new File(CommonString.PATH+File.separator+CommonString.VIDEO_SEND_NAME);


        if(file.exists())
        {
         System.out.println("File path "+file.getAbsolutePath());
        }

        try 
        {       
         FileBody filebody=new FileBody(file);
            MultipartEntity multipartEntity = new MultipartEntity();
            multipartEntity.addPart("'password", new StringBody("password"));
            multipartEntity.addPart("'username", new StringBody("username"));
            multipartEntity.addPart("'video_profile_candidate", filebody);
            httpost.setEntity(multipartEntity);

         HttpResponse httpresponse = httpClient.execute(httpost);

         System.out.println("Hiii "+ httpresponse.getStatusLine().getStatusCode());
         Log.i(TAG, "request"+ httpresponse.getStatusLine().getStatusCode());

        }
        catch (Exception e)
        {
         Log.i(TAG, "Exception "+e.getMessage());
         System.out.println("Exception "+e.getMessage());
        }
        System.out.println("text "+response);

1 个答案:

答案 0 :(得分:0)

您确定“application / x-www-urlendcode”。 也许“application / x-www-form-urlencoded”?

相关问题