Php &;转换为&;amp;何时调用$\u POST请求?

Php &;转换为&;amp;何时调用$\u POST请求?,php,android,apache,post,Php,Android,Apache,Post,我们正在开发一个包含2个模块的应用程序 Android应用程序 PHP应用程序 PHP后端应用程序在带有Centos Server的Apache服务器上运行。 Android应用程序基本上是点击图像,将gps坐标等表单信息发送到服务器 现在,在服务器上创建映像文件时会出现问题。android应用程序调用url时,&'字符将替换为&;,有时甚至通过&;&;&;&;&;&这个问题在一些案例中重复出现。一旦发生这种转换,图像文件就无法正确创建 如何解决

我们正在开发一个包含2个模块的应用程序

  • Android应用程序
  • PHP应用程序 PHP后端应用程序在带有Centos Server的Apache服务器上运行。 Android应用程序基本上是点击图像,将gps坐标等表单信息发送到服务器
  • 现在,在服务器上创建映像文件时会出现问题。android应用程序调用url时,&'字符将替换为&;,有时甚至通过&;&;&;&;&;&这个问题在一些案例中重复出现。一旦发生这种转换,图像文件就无法正确创建

    如何解决?

    同样的代码从去年开始正常工作,这个问题从上个月才开始出现

    以下是在服务器端保存图像的代码:

    foreach($_POST as $key => $value) { 
        $_POST[$x] = $value;
    }
    
    $base=$_REQUEST['image'];
    $nm=$_REQUEST['name'];
    $binary=base64_decode($base);
    
    
    if(file_exists("uploaded_images/".$nm.".jpg")) {
    
    unlink("uploaded_images/".$nm.".jpg");
    }
    
    header('Content-Type: bitmap; charset=utf-8');
    $str="uploaded_images/".$nm.".jpg";
    $file = fopen($str, 'wb');
    fwrite($file, $binary);
    fclose($file);
    chmod($file,0777);
    $ok=1;
    echo $ok;
    
    以下是未正确保存图像时遇到的错误日志。 PHP注意:未定义索引:name in/var/www/html/cbd/def/filesubmitnew.PHP 注意:filesubmitnew.php是上述代码的文件名

    在Android应用程序中,url是如何调用的:

    要创建图像,请执行以下操作:

    if(buttontext.equals("Img1"))   {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        v.setImageBitmap(bitmap);
        buttontext="";
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
        byte [] byte_arr = stream.toByteArray();
        String str1 = Base64.encodeBytes(byte_arr);
        System.out.println(""+str1);
        if(feuser.equals("offline_access")){
        System.out.println("++==--SD CARD");
        File externalStorage = Environment.getExternalStorageDirectory();
        File folder = new File(externalStorage.getAbsolutePath() +mainFolder + caseId);
        if (!folder.exists()) {
            folder.mkdir();
        }
        File pictureFile = new File(externalStorage.getAbsolutePath()+mainFolder+caseId, "1.jpg");
        System.out.println(pictureFile);
        pictureFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(pictureFile);
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(str1);
        myOutWriter.close();
        fOut.close();
        Toast.makeText(getBaseContext(),"Done writing SD "+pictureFile,Toast.LENGTH_SHORT).show();
    }
    else    {
    
        Intent i = new Intent ("com.keyboardlabs.newbankge.CameraUploadService");
        try {
            i.putExtra("imageparams", str1);
            i.putExtra("ref_id", caseId);
            i.putExtra("imageId", "1");
            i.putExtra("CaseType",caseType);
        } 
        catch (Exception e) {
            e.printStackTrace();
        }
        getApplicationContext().startService(i);
    }
    
    以下是camerauploadservice

    protected void onHandleIntent(Intent arg0) {
    
        String imageDataBase64encoded =  arg0.getStringExtra("imageparams");
    String caseID = arg0.getStringExtra("ref_id");
    String imageId = arg0.getStringExtra("imageId");
    String caseType =arg0.getStringExtra("CaseType");
    System.out.println("image_ref="+caseID+"iamgeID="+imageId+"caseType="+caseType+" URL="+URL);
    
    callWebService(imageDataBase64encoded,caseID,imageId,caseType);
    }
    
    public void callWebService(String imageData,String refId,String imageId,String caseType){  
    
        HttpClient httpclient = null;
    
    ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("image",imageData));
    nameValuePairs.add(new BasicNameValuePair("ref_id",refId));
    nameValuePairs.add(new BasicNameValuePair("imageId",imageId));
    nameValuePairs.add(new BasicNameValuePair("CaseType",caseType));
    try{
        httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(URL);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        String the_string_response = convertResponseToString(response);
        System.out.println( "Response= " + the_string_response);
    }catch(Exception e){
        System.out.println( "0" + e.getMessage());
        System.out.println("Error in http connection "+e.toString());
    }
    httpclient.getConnectionManager().shutdown();  
    }
    
    protectedvoid onHandleIntent(意图arg0){
    字符串imageDataBase64encoded=arg0.getStringExtra(“imageparams”);
    字符串caseID=arg0.getStringExtra(“ref_id”);
    字符串imageId=arg0.getStringExtra(“imageId”);
    字符串caseType=arg0.getStringExtra(“caseType”);
    System.out.println(“image_ref=“+caseID+”iamgeID=“+imageId+”caseType=“+caseType+”URL=“+URL”);
    callWebService(imageDataBase64encoded、caseID、imageId、caseType);
    }
    public void callWebService(String-imageData、String-refId、String-imageId、String-caseType){
    HttpClient HttpClient=null;
    ArrayList nameValuePairs=新的ArrayList();
    添加(新的BasicNameValuePair(“图像”,imageData));
    添加(新的BasicNameValuePair(“ref_id”,refId));
    添加(新的BasicNameValuePair(“imageId”,imageId));
    添加(新的BasicNameValuePair(“CaseType”,CaseType));
    试一试{
    httpclient=新的DefaultHttpClient();
    HttpPost HttpPost=新的HttpPost(URL);
    setEntity(新的UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response=httpclient.execute(httppost);
    字符串\u字符串\u响应=convertResponseToString(响应);
    System.out.println(“Response=“+the_string_Response”);
    }捕获(例外e){
    System.out.println(“0”+e.getMessage());
    System.out.println(“http连接中的错误”+e.toString());
    }
    httpclient.getConnectionManager().shutdown();
    }
    
    您是否尝试过url编码器,最好与我们共享一个示例url。您的问题需要一个在没有任何Android代码的情况下发布到PHP的请求的工作示例。该请求已经包含
    &实体-那么Android代码就是罪魁祸首。或者它没有-只有这样它才是您的PHP代码。但可以肯定的是,这是您添加的内容,因为PHP不会自动将字符串转义到实体中。@sven:事实上,问题不在PHP或android代码中,因为我也在IIS 7.0服务器的后端使用c#&asp.net代码运行同一个android应用程序。同样的问题也发生在IIS中…因此服务器挂起,我们不得不挂起,我们的移动应用程序停止工作。我们必须重新启动它,应用程序才能工作。但我们在IIS中通过ftp连接发送文件解决了这个问题。我也在php应用程序中实现相同的ftp功能。也许这会让我很喜欢这个问题,但是为什么它不能在POST请求中正常工作,问题的不一致性超出了我的理解。如果同一个应用不能在两个服务器后端工作,我确实认为这个应用坏了,而不是服务器。你真的不想使用FTP作为一种解决方法,这个协议是完全奇怪的,会在几个场合中断。例如,用户将支持允许HTTP但拒绝FTP的代理。