我尝试连接到以下 API https://api.ssg-wsg.sg/grantCalculators/individual。我收到以下错误“禁止访问此 API”。这些技能未来 API 是否存在任何 UAT?谢谢!
我的订阅 [1]:https ://i.stack.imgur.com/5ZgiQ.jpg
我的代码尝试{
if (Session["access_token"]==null)
{
txtResult.Text = "Generate Token first.";
return;
}
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// string url = "https://mock-api.ssg-wsg.sg/grantCalculators/individual";
string url = "https://public-api.ssg-wsg.sg/grantCalculators/individual";
// string url = "https://api.ssg-wsg.sg/grantCalculators/individual";
// string data = "{\"trainingPartnerUen\":\"198201025C11\",\"courseReferenceNumber\":\"TGS-0026008-ES\"}";
string data = "{\"trainingPartnerUen\":\"" + txtUEN.Text + "\",\"courseReferenceNumber\":\"";
data+=txtReferenceNumber.Text+ "\",\"}";
//url = url + data;
WebRequest myReq = WebRequest.Create(url);
myReq.Method = "POST";
string accesTocken = Session["access_token"].ToString();
myReq.ContentType = "application/json";
using (var streamWriter = new StreamWriter(myReq.GetRequestStream()))
{
streamWriter.Write(data);
}
myReq.Headers.Add("Authorization", "Bearer " + accesTocken);
var httpResponse = (HttpWebResponse)myReq.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
txtResult.Text=result;
}
}
catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
txtResult.Text = text;
}
}
catch (Exception ex)
{
txtResult.Text = ex.Message;
}