$username, 'password' => $password ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); try { $result = @file_get_contents($url, false, $context); if ($result === false) { echo "请求失败: " . error_get_last()['message'] . "\n"; } else { echo "登录结果: {$result}\n"; } } catch (Exception $e) { echo "异常: " . $e->getMessage() . "\n"; } echo "\n"; } // 使用curl尝试登录 echo "使用curl尝试登录:\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://mss.nahaichuan.com/index.php/Retail/Login/doLogin_v1'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); $error = curl_error($ch); $info = curl_getinfo($ch); curl_close($ch); echo "CURL响应: {$response}\n"; if (!empty($error)) { echo "CURL错误: {$error}\n"; } echo "HTTP状态码: {$info['http_code']}\n"; echo "\n完成测试\n"; ?>