0
我有一個PHP應用程序,它的帖子可變信息加入燒瓶中的應用程序(其中做了一些計算,並返回一個結果)。我在win7上本地運行
當我使用postman測試URL「127.0.0.1:5000/index」時,我得到一個200狀態碼(截圖)。然而,當PHP應用程序的帖子在燒瓶應用程序,我得到:
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
我使用curl和冗長的輸出是:
* About to connect() to 127.0.0.1 port 5000 (#0)
* Trying 127.0.0.1...
* connected
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> POST /index/ HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
Host: 127.0.0.1:5000
Accept: */*
Content-Length: 338
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------d5cb02e2edea
< HTTP/1.1 100 Continue
* HTTP 1.0, assume close after body
< HTTP/1.0 404 NOT FOUND
< Content-Type: text/html
< Content-Length: 233
< Server: Werkzeug/0.10.4 Python/2.7.5
我的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()
我在做什麼錯了?
我的心理調試權力說,你應該從'$ url'刪除尾隨斜線:-) – mavroprovato
謝謝,工作的部分「唯一URL /重定向行爲」。你想將它作爲答案輸入嗎? – user61629
好的,我已經加入了 – mavroprovato