Translate a piece of PHP cURL code to C# -



Translate a piece of PHP cURL code to C# -

i'm trying translate piece of code written fetch info basis's website (the activity tracker). task want accomplish here fetch access_token returned in http response header. there no problem original php code, however, there few curl options don't know how map c#'s webclient implementation. these options include curlopt_returntransfer, curlopt_followlocation , curlopt_cookiesession.

the detail problem listed below, here piece of php code:

$login_data = array( 'username' => $this->username, 'password' => $this->password, ); // initialize curl resource , create login request $ch = curl_init(); curl_setopt_array($ch, array( curlopt_url => 'https://app.mybasis.com/login', curlopt_returntransfer => false, //default: true curlopt_post => true, curlopt_postfields => $login_data, curlopt_followlocation => true, // defulat: true curlopt_header => 1, curlopt_cookiesession => true, curlopt_cookiejar => $this->cookie_jar ));

using code, result be: (which contains access token need)

http/1.1 100 go on http/1.1 302 found date: sun, 22 jun 2014 02:03:47 gmt content-type: text/html; charset=utf-8 content-length: 0 connection: keep-alive server: tornadoserver/3.2 location: https://app.mybasis.com cache-control: max-age=0 set-cookie: access_token=f0659120d52f3fde9edfw1d908b81f0f; domain=. mybasis.com; expires=sun, 01 jan 2040 00:00:00 gmt; path=/ set-cookie: scope=login; domain=.mybasis.com; expires=sun, 01 jan 2040 00:00:00 gmt; path=/ set-cookie: refresh_token=982ff518bfe114e2c03f360f0dfbfke1; domain=. mybasis.com; expires=sun, 01 jan 2040 00:00:00 gmt; path=/ http/1.1 200 ok server: nginx/1.4.3 date: sun, 22 jun 2014 02:03:47 gmt content-type: text/html; charset=utf-8 content-length: 5619 last-modified: fri, 25 apr 2014 04:42:49 gmt connection: keep-alive vary: accept-encoding etag: "5359e7c9-15f3" accept-ranges: bytes

however, when utilize c# webclient communicate basis below:

var info = new namevaluecollection { { "username", username}, { "password", password}, }; httpwebresponse response = client.uploadvalues("https://app.mybasis.com/login", "post", data); foreach (string name in client.responseheaders.keys) { console.writeline(name+"="+client.responseheaders[name]); }

i this:

connection=keep-alive vary=accept-encoding accept-ranges=bytes content-length=5619 content-type=text/html; charset=utf-8 date=sun, 22 jun 2014 02:17:44 gmt etag="53f3e7c9-99f3" last-modified=fri, 25 apr 2014 04:42:49 gmt server=nginx/1.4.3

as response.

does know why cannot first 2 http responses 3rd 1 only?

in order functionality out of c# looking need utilize http web request api within .net framework. should provide capability looking for.

c# php curl

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -