10-24-2016 11:19 AM - edited 02-03-2024 5:34 PM
Hello.
I need to use ServiceLayer on my server Hana per obtain a Login.
I write this c# code, but when I execute this code, my server Hana replay me with the message Bad Gateway (502)
ServicePointManager.ServerCertificateValidationCallback=(sender, certificate, chain, errors)=>true;string result ="";string json ="{\"CompanyDB\" : \"SBODEMOIT\", \"UserName\": \"manager\", \"Password\": \"manager\"}";
using (var client =new WebClient()){
client.Headers[HttpRequestHeader.ContentType]="application/json";
client.Encoding=Encoding.UTF8;
result = client.UploadString("https://b1dbhana:50000/Login","POST", json;}
And so I try to use Arc (Advanced rest Client Application) for testing Login on my server, it response correctly with a SessionId.
Where is the error in my code?
This is the correct example for login
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate cert,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{ return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://<myServer>:50000/b1s/v1/Login");
httpWebRequest.Accept = "application/json";
httpWebRequest.KeepAlive = true;
httpWebRequest.ServicePoint.Expect100Continue = false;
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.ContentType = " application/json;odata=minimalmetadata;charset=utf-8";
httpWebRequest.Timeout = 10000000;
httpWebRequest.Method = "POST";
httpWebRequest.UserAgent = "Microsoft ADO.NET Data Services";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
CompanyDB = "<myCompany>",
UserName = "<myUsername>",
Password = "<myPassword>"
});
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
Console.WriteLine(streamReader.ReadToEnd());
}
The using command is necessary per disposing streamWriter object.
Alternatively at the using block this is the possibility
var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
string json = new JavaScriptSerializer().Serialize(new
{
CompanyDB = "SBODEMOIT",
UserName = "manager",
Password = "manager"
});
streamWriter.Write(json);
streamWriter.Dispose();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.