【问题标题】:"invalid parameter" error in androidandroid中的“无效参数”错误
【发布时间】:2013-12-27 14:18:19
【问题描述】:

我正在尝试在 PHP 服务器中上传文件。服务器接受包含用户 ID、密码和视频文件的请求。

以下是服务器端代码。

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);

【问题讨论】:

  • 我需要通过 MultipartEntity 发送用户名和密码吗?

标签: android error-handling http-post


【解决方案1】:

您确定“应用程序/x-www-urlendcode”。 也许是“application/x-www-form-urlencoded”?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    相关资源
    最近更新 更多