xy 3 semanas atrás
pai
commit
fc6a072f5f
1 arquivos alterados com 14 adições e 6 exclusões
  1. 14 6
      src/client.php

+ 14 - 6
src/client.php

@@ -32,14 +32,15 @@ class GameClient {
           
         $options = [
             'http' => [
-                'header'  => [
+                'method' => 'POST',
+                'header' => implode("\r\n", [
                     'Content-Type: application/x-protobuf',
                     'X-Protobuf-Schema: common.proto',
-                    'X-Protobuf-Message: common_pack.ReqLogin'
-                ],
-                'method'  => 'POST',
+                    'X-Protobuf-Message: common_pack.ReqLogin',
+                    'Accept: application/x-protobuf' // 明确要求返回 protobuf 格式
+                ]),
                 'content' => $binaryData,
-                'ignore_errors' => true,
+                'ignore_errors' => false, // 改为 false 以捕获 HTTP 错误
                 'timeout' => 10
             ]
         ];
@@ -47,7 +48,14 @@ class GameClient {
         $context = stream_context_create($options);
 
         try {
-            $response = file_get_contents('http://120.76.130.29:8080/RegLogin', false, $context);
+            $url = 'http://120.76.130.29:8080/RegLogin';
+
+            $response = file_get_contents($url, false, $context);
+            
+            if (strpos($response, '404 page not found') !== false) {
+                throw new Exception("API端点不存在(404),请检查URL: " . $url);
+            }
+
             $userResponse = new ResLogin(); 
             if ($response !== false) {