我目前正在尝试在 C# (API) 中发送 POST 请求,但是我在内容类型和授权方面遇到了一些麻烦,因为它的格式为 apiHash、apiKey。
卷曲示例:
curl -i -XPOST https://sandboxapi.g2a.com/v1/order \
-H "Authorization: qdaiciDiyMaTjxMt, 74026b3dc2c6db6a30a73e71cdb138b1e1b5eb7a97ced46689e2d28db1050875" \
-H 'Content-Type: application/json' \
-d '{"product_id": "10000027819004", "max_price": 45.0}'
API 文档:https : //www.g2a.com/integration-api/documentation/#api-Orders-AddOrder
这是我到目前为止的代码:
private static readonly HttpClient client = new HttpClient();
public async Task < string > makeRequest() {
var values = new Dictionary < string,
string > {
{
"product_id",
"10000027819004"
},
{
"max_price",
"45.0"
}
};
var content = new FormUrlEncodedContent(values);
AuthenticationHeaderValue authHeaders = new AuthenticationHeaderValue("qdaiciDiyMaTjxMt", "74026b3dc2c6db6a30a73e71cdb138b1e1b5eb7a97ced46689e2d28db1050875");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
client.DefaultRequestHeaders.Authorization = authHeaders;
var response = await client.PostAsync("https://sandboxapi.g2a.com/v1/order", content);
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
我尝试了多种解决方案,但似乎无法将它们全部正确(内容类型、授权和参数)。
qq_笑_17
慕容708150
相关分类