Они могли бы поддерживать меня пожалуйста, я стараюсь тратить услугу rest с C#. Это - то, что у меня есть в настоящее время в коде. Я стараюсь тратить услугу post, который производит token. Это консольное приложение. Эта услуга отвечает с этим json используя postman, что, восполняет запас ожидаемая:
Я не знаю, использую ли я формат, приведенный в соответствие для grant_type внутри String. Format
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace Oz
{
class Program
{
//Servicio de cosumo de Web Service con certificados.
//Apunta hacia evaluación
static void Main(string[] args)
{
//VARIABLES
string urlCotizador = "https://internal-apigee-48.us-east-1.elb.as.com:8080/oauth2/v1/token";
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) =>
{
return true;
});
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(urlCotizador);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Headers.Add("Authorization", "Basic RzdXI4dlhsQ1a0Zab0xQ==");
string body = String.Format("grant_type=client_credentials");
try
{
UTF8Encoding encoder1 = new UTF8Encoding();
byte[] arreglo = encoder1.GetBytes(body);
httpWebRequest.ContentLength = arreglo.Length;
Console.WriteLine("Enviado", body);
Stream writer = httpWebRequest.GetRequestStream();
writer.Write(arreglo, 0, arreglo.Length);
WebResponse rb;
rb = httpWebRequest.GetResponse();
Console.WriteLine("Enviado", rb);
writer.Close();
//var response = (HttpWebResponse)httpWebRequest.GetResponse();
//Console.WriteLine(response);
//var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
//Console.WriteLine(responseString);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("No se consume el servicio");
throw new Exception("WebServiceJson: " + e.Message.ToString(), e);
}
}
}
}
Я ничего не посылаю, выполнив проект покажи это. кто-то мог бы ориентироваться?
Даже внизу я помещаю ошибку, которую он показывает мне, выполнив проект
В твоем body, согласно этим показывая в grant_type
тебе остается устанавливать как client_id
, так и client_secret
. Нечто похожее grant_type=client_credentials&client_id=xxxxxxxxxx&client_secret=xxxxxxxxxx
Согласно стандарту Oauth параметры, которые я показал тебе, - обязательные для этого grant_type
и отсюда ошибка http 400 BAD Request