Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';不要将信息发送到REST服务器_C#_Rest_Client_Restsharp - Fatal编程技术网

C# Can';不要将信息发送到REST服务器

C# Can';不要将信息发送到REST服务器,c#,rest,client,restsharp,C#,Rest,Client,Restsharp,我正在使用一个名为RestSharp的REST服务库和C#。我已经尝试了很长时间将信息发送到emailforge(时事通讯服务)服务器,但到目前为止我还没有成功。我可以发布、放置和获取基本信息,但我不能对发送的Json中的字段或列表执行相同的操作 RestClient client = new RestClient(); client.BaseUrl = "https://s3s.fr/api/rest/1/"; client.Authenticator = new HttpBasicAuthe

我正在使用一个名为RestSharp的REST服务库和C#。我已经尝试了很长时间将信息发送到emailforge(时事通讯服务)服务器,但到目前为止我还没有成功。我可以发布、放置和获取基本信息,但我不能对发送的Json中的字段或列表执行相同的操作

RestClient client = new RestClient();
client.BaseUrl = "https://s3s.fr/api/rest/1/";
client.Authenticator = new HttpBasicAuthenticator(splioUser, splioPass);
var request = new RestRequest("{item}", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddUrlSegment("item", "contact");
request.AddParameter("email", "test@test.com.br");
request.AddParameter("firstname", "Jhonny");
request.AddParameter("lastname", "Test");
request.AddParameter("lang", "EN");
这就是结果:

{"email":"test@test.com.br","date":"2013-12-20 18:43:42","firstname":"Jhonny","lastname":"Test","lang":"EN","fields":[{"id":"0","name":"sexo","value":""},{"id":"1","name":"nascimento","value":""},{"id":"2","name":"cidade","value":""},{"id":"3","name":"estado","value":""},{"id":"4","name":"data altera\u00e7\u00e3o do cadastro","value":""},{"id":"5","name":"data \u00faltima compra","value":""},{"id":"6","name":"data primeira compra","value":""},{"id":"7","name":"data de criacao do cadastro","value":""},{"id":"8","name":"data de ultimo login no site","value":""}],"lists":[]}
似乎我不能在“列表”和“字段”值之间包含任何值

有一本手册介绍了如何使用PHP执行此操作:

$universe = 'testapi'; 
$pass = 'MySecretAPIKEY'; 
$resource = ‘contact‘ ; 
$email = ‘old@s3s.fr’ $service_url = "https://$universe:$pass@s3s.fr/api/rest/1/$resource/$email"; 
$curl = curl_init($service_url); 
$query = array ( 'email' => ‘newmail@s3s.fr', 'lang' => 'de', 'fields' => array ( array ( 'id' => '0', 'value' => 'bl10'), array ( 'name' => 'field2', 'value' => 'myothercustomfield_value'), ), 'lists' => array ( array ( 'name' => 'Test Api' ), array ( 'id' => '5', 'action' => 'unsubscribe' ), ), ) ; 
$qstring = json_encode($query); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS,$qstring);
curl_setopt($curl,CURLOPT_HTTPHEADER,array("Expect:")); 
$curl_response = curl_exec($curl);
curl_close($curl); 
var_dump($curl_response); 
var_dump(json_decode($curl_response, true));

提前谢谢

使用RestSharp,您应该使用内置的json序列化。看看这个例子

增加


此外,我发现使用或类似的工具对调试非常有用。Fiddler需要一些工具来监控某些用例的流量,

您是否尝试过生成原始Webrequest而不是使用restsharp?不,我实际上没有。我正在添加一些参数。我已经尝试过这样做:参数[]字段=新参数[3];字段[0]=新参数(){Name=“sexo”,Value=“M”};字段[1]=新参数(){Name=“nascimento”,Value=“11/12/2013”};字段[2]=新参数(){Name=“cidade”,Value=“santos”};request.AddParameter(“字段”,字段);request.AddBody(字段);