2012-04-11 14 views
1

Ich versuche, eine Anwendung zu erstellen, die Daten an Facebook Graph API ohne Verwendung des Libcurl wird Post, Das Problem ist folgendes:Senden HTTP POST in curl-Format mit C#

curl --silent --location 
-F "type=25" 
-F "action_spec={'action.type':'app_use', 'application':195713270451234}" 
"https://graph.facebook.com/act_12345678/adcreatives?access_token=____" 

Jetzt weiß ich, -F var Werte HTTP POST gibt an, aber ich habe keine Ahnung, wie dieses Format senden:

-F "action_spec={'action.type':'app_use', 'application':195713270451234} 

Wenn jemand könnte ich einen Anhaltspunkt darüber, wie es auf eine einfache HTTP-POST-Anforderung konvertieren es genial sein würde. Ich bin froh zu wissen, ob es eine Möglichkeit gibt, den gesamten Curl-Anfrage-String als Anfrage zu senden!

Antwort

2

Goldene Regel:

  • treat Schlüssel-Wert-Paar json Objekte als IDictionary<string, object> oder IDictionary<string, dynamic> oder anonyme Objekte.
  • treat json Arrays als IList<object> oder IList<dynamic>
  • behandeln andere als json Typen als primitive Objekte als bool, string, long, double und so weiter. Hier

ist der Beispielcode:

var actionSpec = new Dictionary<string,object>(); 
actionSpec["action.type"] = "app_use"; 
actionSpec["application"] = 195713270451234; 

var fb = new FacebookClient("access_token"); 
dynamic result = fb.Post("act_12345678/adcreatives", new { type = 25, action_spec = actionSpec }); 
+0

Ich möchte die HTTP-Anforderung von mir schicken und sie wohnen nicht auf dem Facebook-SDK – user1326293