开发者

Zend_Http_Client() equivalent in C#

I found this server side Google Analytics, and I've been trying to convert it into C# code. Everything is going well, but I am not sure what the Zend_Http_Client would be in terms of .net.

I'm using the code here as the reference http://code.google.com/p/serversidegoogleanalytics/ which was built in PHP with the Zend Framework(I assume).

Here are the two methods

    public function getHttpClient () {
        if(!$this->httpClient instanceof Zend_Http_Client) {
            include_once("Zend/Http/Client.php");
            $this->httpClient = new Zend_Http_Client();
            $this->httpClient->setConfig(array(
                'maxredirects' => 1,
                'timeout'      => 4
            ));
            $this->httpClient->setHeaders('Referer', "http://" . self::$trackingDomain . "/");
            $this->httpClient->setHeaders("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)");
            $this->httpClient->setCookieJar();
        }
        return $this->httpClient;
    }

and this

    private function requestHttp($url, $getParams = array())
    {
        $client = $this->getHttpClient();
        $client->setUri($url);
        $client->setParameterGet($getParams);
        $response = $client->request()开发者_运维技巧;

        if ($response->isSuccessful())
            return true;
        else
            return false;
    }

My main concern is the setCokieJar(), MaxRedirects, and Timeouts, setParameterGet(), setURI(), and request()

So what the .net equivalent? WebClient? HttpWebResponse? HttpWebRequest? or is it something else?

Any help will be greatly appreciated.


I've used System.Net.WebClient and System.Net.WebRequest with some success before (I believe WebResponse is just the counterpart to WebRequest). WebClient is easier to use but offers fewer options.


I don't think you'll find an all-in-one equivalent, but WebClient is your best bet for a starting point. HttpWebResponse and HttpWebRequest are a little bit lower level than WebClient. WebClient has some excellent wrappers for making HTTP requests among other things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜