Знатоки, профессионалы помогите разобраться в коде:
Код:
bool authentication()
{
RestRequest authReq = new RestRequest();
authReq.Resource = "authentication/v1/authenticate";
authReq.Method = Method.POST;
authReq.AddHeader("Content-Type", "application/x-www-form-urlencoded");
authReq.AddParameter("client_id", strConsumerKey);
authReq.AddParameter("client_secret", strConsumerSecret);
authReq.AddParameter("grant_type", "client_credentials");
IRestResponse result = _client.Execute(authReq);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
String responseString = result.Content;
int len = responseString.Length;
int index = responseString.IndexOf("\"access_token\":\"") + "\"access_token\":\"".Length;
responseString = responseString.Substring(index, len - index - 1);
int index2 = responseString.IndexOf("\"");
_token = responseString.Substring(0, index2);
updatelistBox1("Token : " + _token);
textBox_token.Text = _token;
//now set the token.
RestRequest setTokenReq = new RestRequest();
setTokenReq.Resource = "utility/v1/settoken";
setTokenReq.Method = Method.POST;
setTokenReq.AddHeader("Content-Type", "application/x-www-form-urlencoded");
setTokenReq.AddParameter("access-token", _token);
IRestResponse resp = _client.Execute(setTokenReq);
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
//done...
updatelistBox1("Set token Successfully");
return true;
}
}
return false;
}
Работаю в Delphi XE5. Накидал на форму компонентов типа RestClient, RestRequest начал что то делать, не получается...