【发布时间】:2017-12-11 07:46:56
【问题描述】:
<html>
<body><input type="button" id="send" value="Send"></body>
</html>
在我的 html 中会有一个按钮, 当它被点击时,我想连接到http://localhost:81/Help/Api/POST-Login 这是我的api。 然后我想向它发布数据。 现在很困惑,任何想法。提前致谢
<?php
$url = "http://localhost:81/Help/Api/POST-Login";
$data = array(
'message' => 'hi,
mobile' => 12345678,
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $data ),
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
【问题讨论】:
-
使用 cURL 进行这种传输。
标签: php asp.net web-services http asp.net-web-api