asp.net - Trouble converting a piece of CURL to C# -
I have the following curl which I am trying to convert to C #. I have no curl experience.
$ ch = curl_init (); curl_setopt_array ($ ch, array (CURLOPT_URL = & gt; 'https://api.lanoba.com/authenticate', CURLOPT_RETURNTRANSFER = & gt; true, CURLOPT_POST = & gt; true, CURLOPT_POSTFIELDS = & gt; array ( ' Tokens' = & gt; $ _POST [ 'token'], 'Apiai_sent' = & gt; 'Your-API-secret')); so far I have this come:
// get a JSON object object to make public square LanobaJSONObject {public string token {; set;} public string api_secret {get; set;}} public void DoAuthenticationCheck () {Var token = Request ["token"]. ToString (); on JSONObject = new LanobaJSONObject () {title} Okn = token, api_secret = "YOUR- API secret"}; Var jsonVal = Jason (Jesnobjekt, Jesnyuefest Bihivier. Elovget); Uri address = new Uri ( "https://api.lanoba.com/authenticate"); HttpWebRequest request = (HttpWebRequest) WebRequest.Create (Address); ServicePointManager.ServerCertificateValidationCallback = Representative {return true; // Always submit cerificate;); request. Method = "post"; Request.ContentType = "text / json"; String reaction = null; (Var stream water = new streamer (using GateRquesteststream ()) {streamWriter.Write (jsonVal); Use} (HttpWebResponse resp = request.GetResponse () as HttpWebResponse) {var reader = new StreamReader (resp.GetResponseStream ()); Feedback = Reader Readout (); } // I keep receiving the error from the provider with a real error description for an error code // So right now I'm assuming I'm doing something wrong on my end} < P> appreciate any help please Edit: Last reply:
Following the help of Okelborg, (thanks!), Here is an example of work:
var wc = New WebClient (); Var wcResponse = wc.UploadValues ( "https://api.lanoba.com/authenticate", new Sistmkclokshns. Specialized Knam Value Collection () {{ "token" request [ "token"]. ToString ( )}, {"API_sent", "your secret-API-"}}); Var decodedResponse = wc.Encoding.GetString (wcResponse); Once again, thanks.
As I type
as far as you can tell you should not send JSON .. :) < / P>
Use UploadStrings / UploadValues (do not miss the real name .. :)) WebClient Class, it's absolutely right you want - it will post a specificity of a name in a given uri and Returns a string with the answer :)
Comments
Post a Comment