Quote:
byte[] byteArray = Encoding.UTF8.GetBytes(strings.ToString());
The
strings
variable is an array of strings.
Calling
.ToString()
on that variable will return the type name:
"System.String[]"
Similarly, passing a string array to
StreamWriter.Write
will call
.ToString()
on that array, and send the literal string
"System.String[]"
to the request.
Hence your request is invalid.
Even if you sent the individual lines correctly, it would not be a correct
application/x-www-form-urlencoded
payload.
Fix your code to send the correct data in the request:
WebRequest webRequest = WebRequest.Create(oAuthType.Auth_URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
const string requestBody = "grant_type=password&username=***&password:**e&scope:esbcom-sms&client_id:ro.****e&client_secret:ro.**e";
webRequest.ContentLength = Encoding.UTF8.GetByteCount(requestBody);
using (StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(requestBody);
}
string responseData;
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
responseData = responseReader.ReadToEnd();
}
If it still doesn't work, then you need to capture your network request and compare it to the request sent by Postman.