从PHP发布到Flas

2024-06-26 14:43:21 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

我有一个php应用程序,它将变量信息发布到flask应用程序(它进行一些计算并返回结果)。我都在win7上运行

当我用postman测试url“127.0.0.1:5000/index”时,我得到一个200状态代码(屏幕截图)。但是当php应用程序发布到flask应用程序时,我得到:

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

我使用的是CURL,详细的输出是:

^{pr2}$

我的php代码如下:

   $data= array('a'=>$a, 'token'=>$token);
   $url="http://127.0.0.1:5000/index/";
   $output = $this->my_model->get_data($url, $data);

public function get_data($url,$postFieldArray=FALSE) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
if ($postFieldArray!= FALSE) {
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFieldArray); //for django
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
.......

return $result;
}

简化烧瓶应用程序:

app = Flask(__name__)
app.debug = True

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/index',methods=['POST'])
def index():

    token = request.form['token']
    a = request.form['a']
    ......
    return

if __name__ == '__main__':
    app.run()

我做错什么了?在


Tags: tokenfalsetrueapp应用程序urldataindex