I am making a system to authenticate the Token (derived from the credit card) next to Cielo.
This token has special characters like +
Cielo receives the data via XML. I made the following code to send:
private String sendHttpRequest(String message)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (Stream stream = request.GetRequestStream())
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes("mensagem=" + message);
stream.Write(bytes, 0, bytes.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string result;
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
}
return result.ToString();
}
But the token arrives in a different way in Cielo returning me Token not found, being the one that generated the Token. When contacting the support of why are their response:
The error occurs when sending the token request without the conversion of URL-encoding, that is, special characters (as an example +) is interpreted as spaces by the platform. This is because platform receives the XML in a parameter of the HTTP request, using the content-type applicationx-www-form-urlencoded. Technologies like Java (Apache HttpComponentHttpClient) perform this conversion automatically, becoming transparent to the developer. O establishment must evaluate and adjust the encoding (URLEncode) in its otherwise, other special characters will same problem.
I think my code is correct when reading this url tried to do something with HttpUtility.UrlEncode (message); ex:
var t = HttpUtility.UrlEncode(message);
byte[] bytes = encoding.GetBytes ("mensagem=" + t);
But the same mistake, before I call there and complain to Cielo would like some help, because I may be commenting some mistake.
Is there any way I can copy the Bytes and try to simulate this post by some plugin from my browser? What do I do with the Chrome REST Client plugin?
How can I debug and visualize something I can help?
NOTE: When the token is without these special characters, the same code above works perfectly.