C# 在C中通过WebClient将PHP发布到URL#
这是我的密码C# 在C中通过WebClient将PHP发布到URL#,c#,php,.net,api,curl,C#,Php,.net,Api,Curl,这是我的密码 $url="http://www.example.com"; $post_data="username=dssasdasd&extension=123"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
$url="http://www.example.com";
$post_data="username=dssasdasd&extension=123";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$status = curl_getinfo($output, CURLINFO_HTTP_CODE);
if ($status == 200)
{echo "Successfully Sended";}
else{echo "Try Again";}
curl_close ($ch);
我需要使用Webclient C#发送此数据。您可以使用此代码示例
string url = "http://Example.com/admin"
using (WebClient client = new WebClient())
{
var data = new NameValueCollection();
data.Add("username","asdsdsad");
data.Add("extension", 123);
var Bytecode = client.UploadValues(url, data);
string htmlCode = Encoding.UTF8.GetString(Bytecode, 0, Bytecode.Length);
// Or you can get the file content without saving it:
}
最后,您将得到HTML代码中的响应