Connexion à un service d'authenfication en async (API DSN Net-entreprise)
Bonjour à tous,
Je suis entrain de mettre en place la connexion à l'API net-entreprises.
La connexion se fait en 2 étape.
La doc indique:
Citation:
1. Appel du service d authentification d un déclarant
2. Passage du jeton V2 à chaque appel de service métier
Exemple de requête d’authentification d’un déclarant sur net-entreprises.fr:
POST /authentifier/1.0/ HTTP/1.1 Host: net-entreprises.fr
User-Agent: Client-DSN (DsnBuilder/12.5; Paie.fr)
Content-Type: application/xml Content-Length: 4096
<identifiants>
<siret>12345678901234</siret>
<nom>Wallace</nom>
<prenom>William</prenom>
<motdepasse>azerty42</motdepasse>
<service>25</service>
</identifiants>
J'ai essayé le code ci-dessous mais l'objet response contient "StatusCode: 401, Authorization Required'"
Une idée ?
Merci.
PS: Si quelqu'un a un bout de code pour l'utilisation des services net-entreprises, je suis preneur.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
string Identification =
"<identifiants>"
+ " <siret>12345678901234</siret>"
+ "<nom>Wallace</nom> "
+ "<prenom>William</prenom>"
+ "<motdepasse>azerty42</motdepasse>"
+ "<service>97</service>"
+"</identifiants>";
// service = 25 si prod et 97 si environnement de test
HttpClient client = new HttpClient();
StringContent vHttpContent = new StringContent( Identification, Encoding.UTF8, "application/xml");
try
{
HttpResponseMessage response = await client.PostAsync("https://test-services.net-entreprises.fr/authentifier/1.0/",
vHttpContent);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
} |