[英]“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.