2016-04-14 37 views
0

POST請求特殊字符我有這樣的C#方法在內部C#應用程序

public void TestMethod1() 
{ 
    string login = @"partone\[email protected]" ; 
    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參數。

所以我需要知道我該如何解決這個問題?

+0

嘗試使用正斜槓。 – jdweng

+0

RestSharp DLL或REST端點引發錯誤嗎? – CathalMF

回答

0

該問題可能與接收Rest端點有關。

通過查看RestSharp代碼,它正確地序列化\字符。

所以當生成JSON時,它會將您的登錄信息變成"partone\\[email protected]",其中有兩個\\。你需要確保端點正確解析回到partone\[email protected]

它也有點奇怪,錯誤是說它是一個無效的參數,因爲你是在身體發送它。

更奇怪的是,在您的示例代碼中,您試圖發佈到WSDL網址。 WSDL用於SOAP Web服務而不是安靜的Web服務。

+0

結果是什麼問題? – CathalMF