c# 应用程序中 post 请求中的特殊字符
Special character in post request within c# application
我有这个 c# 方法
public void TestMethod1()
{
string login = @"partone\afif@gmail.com" ;
string pwd = "ksLLHddf5El";
var request = new RestRequest("https://secureapp4.idshost.fr/authenticationids/restloginservice.php", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-type", "application/json;charset=utf-8");
request.AddBody(new { authentifier = login, password = pwd });
RestClient client = new RestClient();
var response = client.Execute(request);
var data = response.Content;
}
问题是登录字符串中的特殊字符\
,它生成了无效的authentifier
参数。
所以我需要知道如何解决这个问题?
问题可能与接收 Rest 端点有关。
查看 RestSharp 代码后,它正确地序列化了 \ 字符。
因此,当生成 JSON 时,它会将您的登录名变成 "partone\afif@gmail.com"
和两个 \
。您需要确保端点正确地将其解析回 partone\afif@gmail.com
也有点奇怪,错误是说它是一个无效参数,因为你是在正文中发送它。
更奇怪的是,在您的示例代码中,您正试图 post 到 WSDL url。 WSDL 用于 SOAP 网络服务,而不是 restful 网络服务。
我有这个 c# 方法
public void TestMethod1()
{
string login = @"partone\afif@gmail.com" ;
string pwd = "ksLLHddf5El";
var request = new RestRequest("https://secureapp4.idshost.fr/authenticationids/restloginservice.php", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-type", "application/json;charset=utf-8");
request.AddBody(new { authentifier = login, password = pwd });
RestClient client = new RestClient();
var response = client.Execute(request);
var data = response.Content;
}
问题是登录字符串中的特殊字符\
,它生成了无效的authentifier
参数。
所以我需要知道如何解决这个问题?
问题可能与接收 Rest 端点有关。
查看 RestSharp 代码后,它正确地序列化了 \ 字符。
因此,当生成 JSON 时,它会将您的登录名变成 "partone\afif@gmail.com"
和两个 \
。您需要确保端点正确地将其解析回 partone\afif@gmail.com
也有点奇怪,错误是说它是一个无效参数,因为你是在正文中发送它。
更奇怪的是,在您的示例代码中,您正试图 post 到 WSDL url。 WSDL 用于 SOAP 网络服务,而不是 restful 网络服务。