Porting PHP Curl request to C# -


repeat php curl request on c#

i'm trying send request server whois, using curl on c#.

i have php function, works perfectly!

function sendrequest() {     $ch = curl_init();     curl_setopt($ch, curlopt_url, "http://whois.ripn.net");     curl_setopt($ch, curlopt_port, 43);     curl_setopt($ch, curlopt_timeout, 5);     curl_setopt($ch, curlopt_customrequest, "ya.ru\r\n");     $data = curl_exec($ch);     curl_close($ch);     return $data; } 

i try repeat in c #, nothing works.

class curl {      private static easy easy;     private static string sockbuff;      public void curlinit()     {          curl.globalinit((int)curlinitflag.curl_global_all);       }      public void req()     {         easy = new easy();         sockbuff = "";          try         {             easy.writefunction wf = new easy.writefunction(onwritedata);              easy.setopt(curloption.curlopt_url, "http://whois.ripn.net");             easy.setopt(curloption.curlopt_port, "43");             easy.setopt(curloption.curlopt_timeout, "10");             easy.setopt(curloption.curlopt_customrequest, "ya.ru\r\n");             easy.setopt(curloption.curlopt_writefunction, wf);                             easy.perform();             easy.cleanup();          }         catch         {          }         console.write(sockbuff);      }       public static int32 onwritedata(byte[] buf, int32 size, int32 nmemb, object extradata)     {         // console.write(system.text.encoding.utf8.getstring(buf));         sockbuff = sockbuff + system.text.encoding.utf8.getstring(buf);          return size * nmemb;     }   } 

why c# code don't work?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -