gpt4 book ai didi

c# - 指定的值包含无效的 HTTP header 字符

转载 作者:行者123 更新时间:2023-12-04 12:48:47 25 4
gpt4 key购买 nike

我正在尝试从 ASP.NET 站点通过他们的 REST API 访问 WOWZA Streaming Cloud,但是在 RESTSharp 方面经验不足。

这是我尝试创建的 curl 示例:

curl -H 'wsc-api-key: KEY' -H 'wsc-access-key: KEY' -H 'Content-Type:
application/json' -X POST -d '{"live_stream": {"name": "MyNewLiveStream",
"transcoder_type": "transcoded", "billing_mode": "pay_as_you_go",
"broadcast_location": "us_west_california", "encoder": "other_rtmp",
"delivery_method": "push", "aspect_ratio_width": 1920,
"aspect_ratio_height": 1080}}'https://api.cloud.wowza.com/api/v1/live_streams/

参见:https://sandbox.cloud.wowza.com/apidocs/v1/

这是我使用的 C# 代码:

var client = new RestClient("https://api.cloud.wowza.com/");
var newRequest = new RestRequest("api/v1/live_streams",Method.POST);
newRequest.AddHeader("wsc-api-key", ConfigurationManager.AppSettings["WowzaAPIKey"]);
newRequest.AddHeader("wsc-access-key", ConfigurationManager.AppSettings["WowzaAccessKey"]);
newRequest.AddHeader("Content-Type", "application/json");
var body = "{\"live_stream\": {" +
"\"aspect_ratio_height\": 720," +
"\"aspect_ratio_width\": 1280," +
"\"billing_mode\": \"pay_as_you_go\"," +
"\"broadcast_location\": \"us_west_california\"," +
"\"closed_caption_type\": \"none\"," +
"\"delivery_method\": \"push\"," +
"\"encoder\": \"wowza_gocoder\"," +
"\"hosted_page\": true," +
"\"hosted_page_sharing_icons\": true," +
"\"name\": \"MyLiveStream\"," +
"\"player_countdown\": false," +
"\"player_responsive\": true," +
"\"player_type\": \"original_html5\"," +
"\"player_width\": 0," +
"\"recording\": false," +
"\"target_delivery_protocol\": \"hls\"," +
"\"transcoder_type\": \"transcoded\"," +
"\"use_stream_source\": false}";

newRequest.AddJsonBody(body);
IRestResponse myResponse = client.Execute(newRequest);

根据响应修改后,响应码为

"{\"meta\":{\"status\":401,\"code\":\"ERR-401-InvalidApiKey\",\"title\":\"Invalid Api Key Error\",\"message\":\"Invalid API key.\",\"description\":\"\",\"links\":[]}}"

最佳答案

你的 header 是错误的 - 你不需要在值中重复内容类型并从 api-key 名称中删除 ::

 newRequest.AddParameter("content-type", "application/json"); 
newRequest.AddParameter("wsc-api-key", ConfigurationManager.AppSettings["WowzaAPIKey"]);

随着 OP 更新问题而更新

所以现在修改后,调用正常了。当前错误是关于您传递的无效 api key - 可能是您传递的访问 key /api key 无效/已过期。

关于c# - 指定的值包含无效的 HTTP header 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41870400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com