Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java向PHP服务器发送POST数据被accessRules方法阻止_Java_Php_Swing_Yii_Access Rules - Fatal编程技术网

Java向PHP服务器发送POST数据被accessRules方法阻止

Java向PHP服务器发送POST数据被accessRules方法阻止,java,php,swing,yii,access-rules,Java,Php,Swing,Yii,Access Rules,我正在将一些数据发布到Yii框架中的PHP服务器。 登录工作正常。这意味着我的数据会被发送到服务器 但是在登录之后,我的后续请求被服务器上的accessRules方法拒绝,我得到了登录页面的响应 这是PHP中的accessRules函数。 其中,egineering是管理员以外的普通用户 public function accessRules() { return array( array('allow', // allow all users

我正在将一些数据发布到Yii框架中的PHP服务器。 登录工作正常。这意味着我的数据会被发送到服务器

但是在登录之后,我的后续请求被服务器上的
accessRules
方法拒绝,我得到了登录页面的响应

这是PHP中的accessRules函数。 其中,egineering是管理员以外的普通用户

public function accessRules()
    {
        return array(

            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view','AssignedUsers',),
                'roles'=>array('admin', 'engineering'),
                //'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update','userReport','userNewReport',),
                'roles'=>array('admin'),
                //'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' action
                'actions'=>array('admin'),
                'roles'=>array('admin', 'engineering'),
            ),
            array('allow', // allow admin user to perform 'delete' action
                'actions'=>array('delete'),
                'roles'=>array('admin', 'admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }
但是我被服务器拒绝了

这是JAVA请求

String content ="user=" + URLEncoder.encode(userId,encoding) +
"&apiKey=" + URLEncoder.encode(apiKey,encoding);  
以下内容与url一起使用

        connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches (false);
        connection.setRequestProperty("Content-length",String.valueOf (content.length())); 
        connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

        DataOutputStream printout = new DataOutputStream (connection.getOutputStream ());

        System.out.println(url+",Content = "+content);

        printout.writeBytes (content);
        printout.flush ();
        printout.close ();
发送饼干

当你登录时。。。将在服务器中创建会话,会话id将作为http响应头上的cookie发送

您必须从登录响应中捕获这些cookie,并在后续请求中继续发送这些cookie


我刚在谷歌上搜索了一下,发现了这样一个例子:

为什么这个问题上有Swing标签?@Robin他喜欢在编码时跳舞。因为我使用java Swing,但很有趣……可能是你在项目中的某个地方使用Swing,但它与这个问题有什么关系?