dongnvwang8591
2013-09-05 09:43
浏览 52

在C#中通过WebClient将PHP发布到URL

Here my code is

$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);

I need to send this data using Webclient C#.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshi3061 2013-09-05 09:51
    已采纳

    You can use this code sample

                 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:
    
                 }
    

    Finally, You will get response in htmcode

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题