I need to integrate with a third-party API. To use this service, I have to "POST" to a specific URL with specific parameters.
Sample code provided by the service is in php and looks like this
$data = array('From' => '0999999', 'To' => '08888888'); $curl = curl_init(); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); <--- Ignore SSL warnings curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
I am trying to use the WebRequest class to achieve the same in .net. However, I am a bit confused about how to set the post parameters data. I realized that the $ data above is nothing more than a dictionary. So I created an equivalent dictionary. However, how to set message parameters with dictionary values?
At http://msdn.microsoft.com/en-us/library/debx8sh9.aspx they serialize the string into an array of bytes, and then set it as a post parameter to the dataStream. How do I do the same for a dictionary?
Or is my approach wrong? Is there a better way to do this?
source share