2014-02-24 228 views
0

我該怎麼做ASP.Net(C#)我該怎麼做Asp.Net?

//<?php 

$host = "https://****/"; 

$curl = curl_init($host); 


// examp is username, 1 is password for Luna Payment 
curl_setopt($curl, CURLOPT_USERPWD, "examp:1"); 

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 

curl_setopt($curl, CURLOPT_AUTOREFERER, true); 

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, true); 

curl_setopt($curl, CURLOPT_TIMEOUT, 80); 

curl_setopt($curl, CURLOPT_MAXREDIRS, 3); 

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); 

$raw_result = curl_exec($curl); 

$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

curl_close($curl); 


$response = json_decode($raw_result, true); 

if ($response['status'] == 'OK') { 

echo "Completed"; 

} else if ($response['status'] == 'Incomplete') { 

echo "Error: No "; 

} else { 

$last_transaction = end($response['transactions']); 

echo "Error: " . $last_transaction['error_message']; 

} 
+0

搜索HttpWebRequest的,你會發現教程。這是Curl在Asp.Net – Kuzgun

+0

中的等價性可能的重複http://stackoverflow.com/questions/20315684/curl-to-c-sharp-httpwebrequest –

回答

0
WebRequest req = WebRequest.Create(URI); 

    req.Headers.Add("Authorization: OAuth "); 
    req.Headers.Add("X-PrettyPrint:1"); 
    req.Method = "GET"; 
    req.Timeout = 30000; 
    req.ContentType = "application/json"; 
    //you can add remaining things like req.Headers.Add("password:XYZ"); 

    WebResponse resp = req.GetResponse(); 
    if(((HttpWebResponse)(resp)).StatusCode = "OK") 
    { 
    ..... 
    } 
    else 
    { 
    ..... 
    }