Php code, read for a long time, still do not understand. Who can translate it into c #'s publicfunctionget_userinfo ($ uid) {$ paramsarray (); $ params [uid] $ uid; return $ this-post ($ params, api. tuan.2345.comapigetUserInfo. php);} privatefunctionpost ($ data, $ url
Php code, read for a long time, still do not understand. Who can translate it into public function get_userinfo ($ uid) {$ params = array (); $ params ['uid'] = $ uid; return $ this-post ($ params, "http://api.tuan.2345.com/api/getUserInfo.php");} private function post ($ data, $ url
Php code, read for a long time, still do not understand. Who can translate it into c #
Public function get_userinfo ($ uid ){
$ Params = array ();
$ Params ['uid'] = $ uid;
Return $ this-> post ($ params, "http://api.tuan.2345.com/api/getUserInfo.php ");
}
Private function post ($ data, $ url)
{/*{{{*/
// Get parts of URL
$ Url = parse_url ($ url );
If (! $ Url) {return "couldn't parse url ";}
// Provide defaults for port and query string
If (! Isset ($ url ['Port']) {$ url ['Port'] = "";}
If (! Isset ($ url ['query']) {$ url ['query'] = "";}
// Build POST string
$ Encoded = "";
Foreach ($ data as $ k => $ v ){
$ Encoded. = ($ encoded? "&":"");
$ Encoded. = rawurlencode ($ k). "=". rawurlencode ($ v );
}
// Open socket on host
// $ Encoded/* string */= uid = % A1 % B0608496 % A1 % B1
$ Fp = @ fsockopen ($ url ['host'], $ url ['Port']? $ Url ['Port']: 80 );
If (! $ Fp) {return "failed to open socket to {$ url ['host']}";}
// Send HTTP 1.0 POST request to host
Fputs ($ fp, sprintf ("POST % s HTTP/1.0 \ n", $ url ['path'], $ url ['query']? "? ":" ", $ Url ['query']);
Fputs ($ fp, "Host: {$ url ['host']} \ n ");
Fputs ($ fp, "Content-type: application/x-www-form-urlencoded \ n ");
Fputs ($ fp, "Content-length:". strlen ($ encoded). "\ n ");
Fputs ($ fp, "Connection: close \ n ");
Fputs ($ fp, "$ encoded \ n ");
// Read the first line of data, only accept if 200 OK is sent
$ Line = fgets ($ fp, 1024 );
If (! Preg_match ('# ^ HTTP/1 \\.. 200 #', $ line) {return ;}
// Put everything, cannot the headers to $ results
$ Results = "";
$ Inheader = TRUE;
While (! Feof ($ fp )){
$ Line = fgets ($ fp, 1024 );
If ($ inheader & ($ line = "\ n" | $ line = "\ r \ n ")){
$ Inheader = FALSE;
}
Elseif (! $ Inheader ){
$ Results. = $ line;
}
}
Fclose ($ fp );
// Return with data encoded ed
Return $ results;
}/*}}}*/