php代碼
一、php
<?php header("Content-Type:text/html;charset=UTF-8"); $u=$_POST['zdupdate'];$p=$_POST['pid'];$a=$_POST["afid"];$d=$_POST["dtime"];require('../db/conn.php');//打開文件$sql_expire="insert into `m-haibook`.tbl_aff_log(aff_id,p_id,log_date,create_date) values($a,$p,'$d',now())";if($u=='Y'){ $myconn = mysql_connect($server_name, $db_username, $db_password);mysql_select_db($db_name);mysql_query("set names 'utf8'"); mysql_query($sql_expire);print "1HHhh..1154QQwweeWW";}?>
二、C#代碼
string postString = "zdupdate=Y&pid=" + dt.Rows[i]["Pid"].ToString() + "&afid=" + dt.Rows[i]["affiateid"].ToString() + "&dtime=" + dt.Rows[i]["Dtime"].ToString() + "";//這里即為傳遞的參數,可以用工具抓包分析,也可以自己分析,主要是form里面每一個name都要加進來 byte[] postData = Encoding.UTF8.GetBytes(postString);//編碼,尤其是漢字,事先要看下抓取網頁的編碼方式 string url = "http://haibook.pnxchina.com/api/index.php";//地址 WebClient webClient = new WebClient();webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必須加的header,如果改為GET方式的話就去掉這句話即可 byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流 string srcString = Encoding.UTF8.GetString(responseData);//解碼
以上所述是小編給大家介紹的C#打開php鏈接傳參然后接收返回值的關鍵代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答