KennethZero 2019-5-14 17:27
<html>
<form action="http://XXXX/Token" method="post">
<input type="hidden" name="username" value="admin" />
<input type="hidden" name="password" value="password" />
<input type="hidden" name="grant_type" value="password" />
<input type="submit" value="Send data" >
</form>
</html>
JSON 回覆係
{"access_token":"cnjdnjfdnxnxjknxxcdfkn","token_type":"bearer","expires_in":604799}
想係返本身的HTML display 出黎,應該點做
sinson123 2019-5-15 17:57
點解唔直接用ajax做???
中環創新小子 2019-5-15 23:06
[quote]原帖由 [i]sinson123[/i] 於 2019-5-15 05:57 PM 發表 [url=https://computer.discuss.com.hk/redirect.php?goto=findpost&pid=499374280&ptid=28218193][img]https://computer.discuss.com.hk/images/common/back.gif[/img][/url]
點解唔直接用ajax做??? [/quote]
應該用 ajax,最簡單可以用 JQuery 處理。
KennethZero 2019-5-17 18:34
<html>
<form action="http://1.1.1.1/Server/Token" method="post">
<input type="hidden" name="username" value="admin" />
<input type="hidden" name="password" value="password" />
<input type="hidden" name="grant_type" value="password" />
<input type="submit" value="Send data" >
</form>
</html>
我想將依段CODE轉做PHP
<?php
$url = 'http://1.1.1.1/Server/Token';
// Two variables to send via POST
$form_data = array('grant_type' => 'password','usernmae' => 'admin',
'password' => 'password');
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
// This should be a POST request
curl_setopt($c, CURLOPT_POST, true);
// This is a request containing JSON
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// This is the data to send, formatted appropriately
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($form_data));
print curl_exec($c);
?>
但PHP出黎就變左{"error":"invalid_client"}