简体   繁体   English

android中的“无效参数”错误

[英]“invalid parameter” error in android

i am trying to upload a file in Php server.the server accepts a request containing Userid,password and a video file. 我正在尝试在PHP服务器中上传文件。服务器接受包含Userid,密码和视频文件的请求。

following is server side code. 以下是服务器端代码。

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

when ever i am trying to send the request from android through HttpPost getting an "invalid Parameter" error. 每当我尝试通过HttpPost从android发送请求时,都会收到“无效参数”错误。 can anyone help me out. 谁能帮我吗。

here is my android code 这是我的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);

Are you sure about "application/x-www-urlendcode". 您确定要使用“ application / x-www-urlendcode”吗? Maybe "application/x-www-form-urlencoded"? 也许是“应用程序/ x-www-form-urlencoded”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 首次登录Facebook Android SDK后,获取无效的android_key参数错误 - Getting invalid android_key parameter error, after first time login in Facebook Android SDK 尝试为 Android 制作 hello world 示例时出现“无效的命令行参数”错误 - “invalid command-line parameter” error while trying to make a hello world example for Android 类内部的Java内部接口在Xamarin android绑定中抛出无效的参数类型错误 - java internal interface in class throw Invalid parameter type error in xamarin android binding Phonegap构建-Facebook连接插件-无效的android_key参数错误 - Phonegap build - Facebook connect plugin - Invalid android_key parameter error Android Emulator:命令行参数无效 - Android Emulator: invalid command-line parameter Android执行时无效的命令行参数 - Invalid command line parameter when Android executes AWS SNS Android App中的参数无效 - Invalid Parameter in AWS SNS Android App Android webrtc - ICE URI 中的传输参数无效 - Android webrtc - Invalid transport parameter in ICE URI Android ViewModelProvider() 参数错误 - Android ViewModelProvider() parameter error Leaflet中的无效GeoJSON错误-Android - Invalid GeoJSON error in Leaflet - Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM