Repository navigation
Expand file tree
/
Copy pathtest-88code-full-simulation.go
More file actions
156 lines (139 loc) · 4.02 KB
/
Copy pathtest-88code-full-simulation.go
File metadata and controls
156 lines (139 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//go:build ignore
// +build ignore
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"time"
)
// 完整模拟 Claude Code 请求
// Author: Half open flowers
func main() {
apiKey := "88_01f315e7e8ea55846f8088e713a9226f693551df66f535288e613934cb918f4a"
url := "https://m.88code.org/api/v1/messages"
body := `{"model":"claude-sonnet-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":"hi"}]}`
fmt.Println("================================================================")
fmt.Println("完整模拟 Claude Code 请求")
fmt.Println("================================================================\n")
client := &http.Client{Timeout: 30 * time.Second}
tests := []struct {
name string
headers map[string]string
}{
{
name: "1. 最小化 Claude Code headers",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
},
},
{
name: "2. 添加 anthropic-beta",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15",
},
},
{
name: "3. Claude Code User-Agent",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
"User-Agent": "claude-code/1.0.0",
},
},
{
name: "4. Anthropic SDK headers (完整)",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
"User-Agent": "anthropic-typescript/0.39.0",
"x-stainless-lang": "js",
"x-stainless-package-version": "0.39.0",
"x-stainless-os": "Windows",
"x-stainless-arch": "x64",
"x-stainless-runtime": "node",
"x-stainless-runtime-version": "v20.18.0",
},
},
{
name: "5. 添加 Accept headers",
headers: map[string]string{
"Content-Type": "application/json",
"Accept": "text/event-stream",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
},
},
{
name: "6. 使用旧版 anthropic-version",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-01-01",
},
},
{
name: "7. 不带 anthropic-version",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
},
},
{
name: "8. 模拟浏览器请求",
headers: map[string]string{
"Content-Type": "application/json",
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"Accept": "*/*",
"Origin": "vscode-file://vscode-app",
},
},
}
for _, test := range tests {
fmt.Printf("--- %s ---\n", test.name)
req, _ := http.NewRequest("POST", url, bytes.NewBufferString(body))
for k, v := range test.headers {
req.Header.Set(k, v)
}
start := time.Now()
resp, err := client.Do(req)
latency := time.Since(start)
if err != nil {
fmt.Printf("❌ 错误: %v\n\n", err)
continue
}
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
respStr := string(respBody)
isSuccess := resp.StatusCode == 200 &&
(contains(respStr, `"content"`) || contains(respStr, `"text"`)) &&
!contains(respStr, `"error"`)
if isSuccess {
fmt.Printf("✅ HTTP %d (%v) - 成功!\n", resp.StatusCode, latency.Round(time.Millisecond))
} else {
fmt.Printf("❌ HTTP %d (%v)\n", resp.StatusCode, latency.Round(time.Millisecond))
}
if len(respStr) > 150 {
respStr = respStr[:150] + "..."
}
fmt.Printf("响应: %s\n\n", respStr)
}
}
func contains(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}